Loading media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -220,16 +220,15 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat( return AMEDIA_ERROR_INVALID_PARAMETER; } int32_t bitrate; if (!AMediaFormat_getInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, &bitrate)) { status = mMediaSampleReader->getEstimatedBitrateForTrack(mTrackIndex, &bitrate); if (!AMediaFormat_getInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, &mConfiguredBitrate)) { status = mMediaSampleReader->getEstimatedBitrateForTrack(mTrackIndex, &mConfiguredBitrate); if (status != AMEDIA_OK) { LOG(ERROR) << "Unable to estimate bitrate. Using default " << kDefaultBitrateMbps; bitrate = kDefaultBitrateMbps; mConfiguredBitrate = kDefaultBitrateMbps; } LOG(INFO) << "Configuring bitrate " << bitrate; AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, bitrate); LOG(INFO) << "Configuring bitrate " << mConfiguredBitrate; AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, mConfiguredBitrate); } SetDefaultFormatValueFloat(AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, encoderFormat, Loading media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h +2 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: private: friend struct AsyncCodecCallbackDispatch; friend class VideoTrackTranscoderTests; // Minimal blocking queue used as a message queue by VideoTrackTranscoder. template <typename T> Loading Loading @@ -101,6 +102,7 @@ private: uid_t mUid; uint64_t mInputFrameCount = 0; uint64_t mOutputFrameCount = 0; int32_t mConfiguredBitrate = 0; }; } // namespace android Loading media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -86,6 +86,10 @@ public: ~VideoTrackTranscoderTests() { LOG(DEBUG) << "VideoTrackTranscoderTests destroyed"; } static int32_t getConfiguredBitrate(const std::shared_ptr<VideoTrackTranscoder>& transcoder) { return transcoder->mConfiguredBitrate; } std::shared_ptr<MediaSampleReader> mMediaSampleReader; int mTrackIndex; std::shared_ptr<AMediaFormat> mSourceFormat; Loading Loading @@ -140,7 +144,7 @@ TEST_F(VideoTrackTranscoderTests, SampleSoundness) { TEST_F(VideoTrackTranscoderTests, PreserveBitrate) { LOG(DEBUG) << "Testing PreserveBitrate"; auto callback = std::make_shared<TestTrackTranscoderCallback>(); std::shared_ptr<MediaTrackTranscoder> transcoder = VideoTrackTranscoder::create(callback); auto transcoder = VideoTrackTranscoder::create(callback); auto destFormat = TrackTranscoderTestUtils::getDefaultVideoDestinationFormat( mSourceFormat.get(), false /* includeBitrate*/); Loading @@ -155,15 +159,11 @@ TEST_F(VideoTrackTranscoderTests, PreserveBitrate) { ASSERT_TRUE(transcoder->start()); callback->waitUntilTrackFormatAvailable(); auto outputFormat = transcoder->getOutputFormat(); ASSERT_NE(outputFormat, nullptr); transcoder->stop(); EXPECT_EQ(callback->waitUntilFinished(), AMEDIA_OK); int32_t outBitrate; EXPECT_TRUE(AMediaFormat_getInt32(outputFormat.get(), AMEDIAFORMAT_KEY_BIT_RATE, &outBitrate)); int32_t outBitrate = getConfiguredBitrate(transcoder); ASSERT_GT(outBitrate, 0); EXPECT_EQ(srcBitrate, outBitrate); } Loading Loading
media/libmediatranscoding/transcoder/VideoTrackTranscoder.cpp +5 −6 Original line number Diff line number Diff line Loading @@ -220,16 +220,15 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat( return AMEDIA_ERROR_INVALID_PARAMETER; } int32_t bitrate; if (!AMediaFormat_getInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, &bitrate)) { status = mMediaSampleReader->getEstimatedBitrateForTrack(mTrackIndex, &bitrate); if (!AMediaFormat_getInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, &mConfiguredBitrate)) { status = mMediaSampleReader->getEstimatedBitrateForTrack(mTrackIndex, &mConfiguredBitrate); if (status != AMEDIA_OK) { LOG(ERROR) << "Unable to estimate bitrate. Using default " << kDefaultBitrateMbps; bitrate = kDefaultBitrateMbps; mConfiguredBitrate = kDefaultBitrateMbps; } LOG(INFO) << "Configuring bitrate " << bitrate; AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, bitrate); LOG(INFO) << "Configuring bitrate " << mConfiguredBitrate; AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, mConfiguredBitrate); } SetDefaultFormatValueFloat(AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, encoderFormat, Loading
media/libmediatranscoding/transcoder/include/media/VideoTrackTranscoder.h +2 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ public: private: friend struct AsyncCodecCallbackDispatch; friend class VideoTrackTranscoderTests; // Minimal blocking queue used as a message queue by VideoTrackTranscoder. template <typename T> Loading Loading @@ -101,6 +102,7 @@ private: uid_t mUid; uint64_t mInputFrameCount = 0; uint64_t mOutputFrameCount = 0; int32_t mConfiguredBitrate = 0; }; } // namespace android Loading
media/libmediatranscoding/transcoder/tests/VideoTrackTranscoderTests.cpp +7 −7 Original line number Diff line number Diff line Loading @@ -86,6 +86,10 @@ public: ~VideoTrackTranscoderTests() { LOG(DEBUG) << "VideoTrackTranscoderTests destroyed"; } static int32_t getConfiguredBitrate(const std::shared_ptr<VideoTrackTranscoder>& transcoder) { return transcoder->mConfiguredBitrate; } std::shared_ptr<MediaSampleReader> mMediaSampleReader; int mTrackIndex; std::shared_ptr<AMediaFormat> mSourceFormat; Loading Loading @@ -140,7 +144,7 @@ TEST_F(VideoTrackTranscoderTests, SampleSoundness) { TEST_F(VideoTrackTranscoderTests, PreserveBitrate) { LOG(DEBUG) << "Testing PreserveBitrate"; auto callback = std::make_shared<TestTrackTranscoderCallback>(); std::shared_ptr<MediaTrackTranscoder> transcoder = VideoTrackTranscoder::create(callback); auto transcoder = VideoTrackTranscoder::create(callback); auto destFormat = TrackTranscoderTestUtils::getDefaultVideoDestinationFormat( mSourceFormat.get(), false /* includeBitrate*/); Loading @@ -155,15 +159,11 @@ TEST_F(VideoTrackTranscoderTests, PreserveBitrate) { ASSERT_TRUE(transcoder->start()); callback->waitUntilTrackFormatAvailable(); auto outputFormat = transcoder->getOutputFormat(); ASSERT_NE(outputFormat, nullptr); transcoder->stop(); EXPECT_EQ(callback->waitUntilFinished(), AMEDIA_OK); int32_t outBitrate; EXPECT_TRUE(AMediaFormat_getInt32(outputFormat.get(), AMEDIAFORMAT_KEY_BIT_RATE, &outBitrate)); int32_t outBitrate = getConfiguredBitrate(transcoder); ASSERT_GT(outBitrate, 0); EXPECT_EQ(srcBitrate, outBitrate); } Loading