Skip to content

Commit

Permalink
[c2][encoder] AVC encoder low power mode configurable
Browse files Browse the repository at this point in the history
Make AVC encoder low power mode configurable in
media_codecs_intel_c2_video.xml.

Tracked-On: OAM-123091
Signed-off-by: Lina Sun <[email protected]>
  • Loading branch information
lsun30 authored and sysopenci committed Aug 20, 2024
1 parent 2779e99 commit 7d03744
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 32 deletions.
1 change: 1 addition & 0 deletions c2_components/include/mfx_c2_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class MfxC2Component : public C2ComponentInterface,
int flags{0};
bool dump_output{false};
uint32_t concurrent_instances{0};
bool low_power_mode{false};
};
protected:
/* State diagram:
Expand Down
6 changes: 6 additions & 0 deletions c2_components/src/mfx_c2_encoder_component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,12 @@ mfxStatus MfxC2EncoderComponent::ResetSettings()
m_mfxVideoParamsConfig.NumExtParam = 0;
m_mfxVideoParamsConfig.ExtParam = nullptr;

// set low power mode for AVC encoder
if(m_mfxVideoParamsConfig.mfx.CodecId == MFX_CODEC_AVC && m_createConfig.low_power_mode)
{
m_mfxVideoParamsConfig.mfx.LowPower = MFX_CODINGOPTION_ON;
}

MFX_DEBUG_TRACE__mfxStatus(mfx_res);
return mfx_res;
}
Expand Down
1 change: 1 addition & 0 deletions c2_store/src/mfx_c2_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ c2_status_t MfxC2ComponentStore::readConfigFile()
config.flags = flags;
config.dump_output = m_xmlParser.dumpOutputEnabled(name.c_str());
config.concurrent_instances = m_xmlParser.getConcurrentInstances(name.c_str());
config.low_power_mode = m_xmlParser.getLowPowerMode(name.c_str());

m_componentsRegistry_.emplace(name, ComponentDesc(module.c_str(), media_type.c_str(), kind, config));
}
Expand Down
4 changes: 2 additions & 2 deletions c2_utils/include/mfx_c2_xml_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MfxXmlParser
C2String getMediaType(const char *name);
uint32_t getConcurrentInstances(const char *name);
bool dumpOutputEnabled(const char *name);
bool getLowPowerMode(const char *name);

private:

Expand All @@ -62,6 +63,7 @@ class MfxXmlParser
std::map<C2String, AttributeMap> typeMap; // map of types supported by this codec
bool dump_output{false};
uint32_t concurrentInstance{0};
bool lowPowerMode{false};
};

enum Section {
Expand All @@ -79,8 +81,6 @@ class MfxXmlParser

c2_status_t addMediaCodecFromAttributes(bool encoder, const char **attrs);

c2_status_t addDiagnostics(const char **attrs);

c2_status_t addLimits(const char **attrs);

void startElementHandler(const char *name, const char **attrs);
Expand Down
62 changes: 32 additions & 30 deletions c2_utils/src/mfx_c2_xml_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ bool MfxXmlParser::dumpOutputEnabled(const char *name) {
return codec->second.dump_output;
}

bool MfxXmlParser::getLowPowerMode(const char *name) {

MFX_DEBUG_TRACE_FUNC;

auto codec = m_codecMap.find(name);
if (codec == m_codecMap.end()) {
MFX_DEBUG_TRACE_STREAM("codec " << name << "wasn't found");
return false;
}
return codec->second.lowPowerMode;
}

c2_status_t MfxXmlParser::addMediaCodecFromAttributes(bool encoder, const char** attrs) {

MFX_DEBUG_TRACE_FUNC;
Expand Down Expand Up @@ -165,44 +177,37 @@ static bool parseBoolean(const char* s) {
strcasecmp(s, "1") == 0;
}

c2_status_t MfxXmlParser::addDiagnostics(const char **attrs) {
MFX_DEBUG_TRACE_FUNC;

bool dump_output{false};

size_t i = 0;
while (attrs[i] != nullptr) {
if (strcmp(attrs[i], "dumpOutput") == 0) {
if (attrs[++i] == nullptr) {
MFX_DEBUG_TRACE_STREAM("dumpOutput is null");
return C2_BAD_VALUE;
}
dump_output = parseBoolean(attrs[i]);
MFX_DEBUG_TRACE_STREAM("dumpOutput value " << attrs[i] << " parsed to " << (int)dump_output);
} else {
MFX_DEBUG_TRACE_STREAM("unrecognized attribute: " << attrs[i]);
return C2_BAD_VALUE;
}
++i;
}

m_currentCodec->second.dump_output = dump_output;
return C2_OK;
}

c2_status_t MfxXmlParser::addLimits(const char **attrs) {
MFX_DEBUG_TRACE_FUNC;

size_t i = 0;
while (attrs[i] != nullptr) {
if (strcmp(attrs[i], "concurrent-instances") == 0) {
if (strcmp(attrs[++i], "max") == 0) {
m_currentCodec->second.concurrentInstance = std::atoi(attrs[++i]);
MFX_DEBUG_TRACE_STREAM("m_currentCodec->second.concurrentInstance = %d", m_currentCodec->second.concurrentInstance);
MFX_DEBUG_TRACE_PRINTF("m_currentCodec->second.concurrentInstance = %d", m_currentCodec->second.concurrentInstance);
} else {
MFX_DEBUG_TRACE_MSG("concurrent-instances is null");
return C2_BAD_VALUE;
}
} else if (strcmp(attrs[i], "dumpOutput") == 0) {
if (strcmp(attrs[++i], "value") == 0) {
m_currentCodec->second.dump_output = parseBoolean(attrs[++i]);
MFX_DEBUG_TRACE_PRINTF("m_currentCodec->second.dump_output = %d", m_currentCodec->second.dump_output);
} else {
MFX_DEBUG_TRACE_MSG("dumpOutput is null");
return C2_BAD_VALUE;
}
} else if (strcmp(attrs[i], "lowPowerMode") == 0) {
if (strcmp(attrs[++i], "value") == 0) {
m_currentCodec->second.lowPowerMode = parseBoolean(attrs[++i]);
MFX_DEBUG_TRACE_PRINTF("m_currentCodec->second.lowPowerMode = %d ", m_currentCodec->second.lowPowerMode);
} else {
MFX_DEBUG_TRACE_MSG("lowPowerMode is null");
return C2_BAD_VALUE;
}
}

i++;
}

Expand Down Expand Up @@ -262,10 +267,7 @@ void MfxXmlParser::startElementHandler(const char* name, const char** attrs) {
case SECTION_DECODER:
case SECTION_ENCODER:
{
if (strcmp(name, "Diagnostics") == 0) {
m_parsingStatus =
addDiagnostics(attrs);
} else if (strcmp(name, "Limit") == 0) {
if (strcmp(name, "Limit") == 0) {
addLimits(attrs);
}
break;
Expand Down

0 comments on commit 7d03744

Please sign in to comment.