Transcoder: Don't preserve profile/level when switching codec.
Avoid configuring encoder with source file's profile and level
if the codec type itself will change. Instead leave the default
unspecified. The caller can still set profile/level when
configuring the transcoder.
Bug: 182576621
Test: Transcoder unit tests.
Change-Id: I469a7a397ebf3e2eade6a48d95851656157578b7
diff --git a/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp b/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
index bcbef6f..038afd2 100644
--- a/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
+++ b/media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp
@@ -173,7 +173,7 @@
if (auto transcoder = wrapper->getTranscoder()) {
const bool isDecoder = codec == transcoder->mDecoder;
const char* kCodecName = (isDecoder ? "Decoder" : "Encoder");
- LOG(DEBUG) << kCodecName << " format changed: " << AMediaFormat_toString(format);
+ LOG(INFO) << kCodecName << " format changed: " << AMediaFormat_toString(format);
transcoder->mCodecMessageQueue.push([transcoder, format, isDecoder] {
transcoder->updateTrackFormat(format, isDecoder);
});
@@ -306,7 +306,7 @@
}
mEncoder = std::make_shared<CodecWrapper>(encoder, shared_from_this());
- LOG(DEBUG) << "Configuring encoder with: " << AMediaFormat_toString(mDestinationFormat.get());
+ LOG(INFO) << "Configuring encoder with: " << AMediaFormat_toString(mDestinationFormat.get());
status = AMediaCodec_configure(mEncoder->getCodec(), mDestinationFormat.get(),
NULL /* surface */, NULL /* crypto */,
AMEDIACODEC_CONFIGURE_FLAG_ENCODE);
@@ -358,15 +358,13 @@
AMediaFormat_setInt32(decoderFormat.get(), TBD_AMEDIACODEC_PARAMETER_KEY_ALLOW_FRAME_DROP, 0);
// Copy over configurations that apply to both encoder and decoder.
- static const EntryCopier kEncoderEntriesToCopy[] = {
+ static const std::vector<EntryCopier> kEncoderEntriesToCopy{
ENTRY_COPIER2(AMEDIAFORMAT_KEY_OPERATING_RATE, Float, Int32),
ENTRY_COPIER(AMEDIAFORMAT_KEY_PRIORITY, Int32),
};
- const size_t entryCount = sizeof(kEncoderEntriesToCopy) / sizeof(kEncoderEntriesToCopy[0]);
- CopyFormatEntries(mDestinationFormat.get(), decoderFormat.get(), kEncoderEntriesToCopy,
- entryCount);
+ CopyFormatEntries(mDestinationFormat.get(), decoderFormat.get(), kEncoderEntriesToCopy);
- LOG(DEBUG) << "Configuring decoder with: " << AMediaFormat_toString(decoderFormat.get());
+ LOG(INFO) << "Configuring decoder with: " << AMediaFormat_toString(decoderFormat.get());
status = AMediaCodec_configure(mDecoder, decoderFormat.get(), mSurface, NULL /* crypto */,
0 /* flags */);
if (status != AMEDIA_OK) {
@@ -513,9 +511,6 @@
onOutputSampleAvailable(sample);
mLastSampleWasSync = sample->info.flags & SAMPLE_FLAG_SYNC_SAMPLE;
- } else if (bufferIndex == AMEDIACODEC_INFO_OUTPUT_FORMAT_CHANGED) {
- AMediaFormat* newFormat = AMediaCodec_getOutputFormat(mEncoder->getCodec());
- LOG(DEBUG) << "Encoder output format changed: " << AMediaFormat_toString(newFormat);
}
if (bufferInfo.flags & AMEDIACODEC_BUFFER_FLAG_END_OF_STREAM) {
@@ -535,15 +530,14 @@
void VideoTrackTranscoder::updateTrackFormat(AMediaFormat* outputFormat, bool fromDecoder) {
if (fromDecoder) {
- static const AMediaFormatUtils::EntryCopier kValuesToCopy[] = {
+ static const std::vector<AMediaFormatUtils::EntryCopier> kValuesToCopy{
ENTRY_COPIER(AMEDIAFORMAT_KEY_COLOR_RANGE, Int32),
ENTRY_COPIER(AMEDIAFORMAT_KEY_COLOR_STANDARD, Int32),
ENTRY_COPIER(AMEDIAFORMAT_KEY_COLOR_TRANSFER, Int32),
};
AMediaFormat* params = AMediaFormat_new();
if (params != nullptr) {
- AMediaFormatUtils::CopyFormatEntries(outputFormat, params, kValuesToCopy,
- std::size(kValuesToCopy));
+ AMediaFormatUtils::CopyFormatEntries(outputFormat, params, kValuesToCopy);
if (AMediaCodec_setParameters(mEncoder->getCodec(), params) != AMEDIA_OK) {
LOG(WARNING) << "Unable to update encoder with color information";
}
@@ -615,7 +609,7 @@
// TODO: transfer other fields as required.
mActualOutputFormat = std::shared_ptr<AMediaFormat>(formatCopy, &AMediaFormat_delete);
- LOG(DEBUG) << "Actual output format: " << AMediaFormat_toString(formatCopy);
+ LOG(INFO) << "Actual output format: " << AMediaFormat_toString(formatCopy);
notifyTrackFormatAvailable();
}