Transcoder: Preserve source track's bitrate by default.
When no bitrate is passed in the transcoder now preserves the
source track's bitrate. If the bitrate is not available as metadata
the transcoder will sample the source track and estimate the bitrate.
Fixes: 160648740
Test: Unit tests.
Change-Id: I4e0284128aaa1116f5b61d908b52582b2ed3d7e4
diff --git a/media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp b/media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp
index 5f2cd12..4eecd90 100644
--- a/media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp
+++ b/media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp
@@ -23,6 +23,7 @@
#include <fcntl.h>
#include <gtest/gtest.h>
#include <media/MediaSampleReaderNDK.h>
+#include <media/NdkCommon.h>
#include <media/VideoTrackTranscoder.h>
#include <utils/Timers.h>
@@ -66,8 +67,7 @@
if (strncmp(mime, "video/", 6) == 0) {
mTrackIndex = trackIndex;
- mSourceFormat = std::shared_ptr<AMediaFormat>(
- trackFormat, std::bind(AMediaFormat_delete, std::placeholders::_1));
+ mSourceFormat = std::shared_ptr<AMediaFormat>(trackFormat, &AMediaFormat_delete);
ASSERT_NE(mSourceFormat, nullptr);
mDestinationFormat =
@@ -143,6 +143,35 @@
sampleConsumerThread.join();
}
+TEST_F(VideoTrackTranscoderTests, PreserveBitrate) {
+ LOG(DEBUG) << "Testing PreserveBitrate";
+ std::shared_ptr<TestCallback> callback = std::make_shared<TestCallback>();
+ std::shared_ptr<MediaTrackTranscoder> transcoder = VideoTrackTranscoder::create(callback);
+
+ auto destFormat = TrackTranscoderTestUtils::getDefaultVideoDestinationFormat(
+ mSourceFormat.get(), false /* includeBitrate*/);
+ EXPECT_NE(destFormat, nullptr);
+
+ ASSERT_EQ(transcoder->configure(mMediaSampleReader, mTrackIndex, destFormat), AMEDIA_OK);
+ ASSERT_TRUE(transcoder->start());
+
+ callback->waitUntilTrackFormatAvailable();
+
+ auto outputFormat = transcoder->getOutputFormat();
+ ASSERT_NE(outputFormat, nullptr);
+
+ ASSERT_TRUE(transcoder->stop());
+ transcoder->getOutputQueue()->abort();
+
+ int32_t outBitrate;
+ EXPECT_TRUE(AMediaFormat_getInt32(outputFormat.get(), AMEDIAFORMAT_KEY_BIT_RATE, &outBitrate));
+
+ int32_t srcBitrate;
+ EXPECT_EQ(mMediaSampleReader->getEstimatedBitrateForTrack(mTrackIndex, &srcBitrate), AMEDIA_OK);
+
+ EXPECT_EQ(srcBitrate, outBitrate);
+}
+
// VideoTrackTranscoder needs a valid destination format.
TEST_F(VideoTrackTranscoderTests, NullDestinationFormat) {
LOG(DEBUG) << "Testing NullDestinationFormat";