Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1184f939 authored by Linus Nilsson's avatar Linus Nilsson
Browse files

Transcoder: Don't fail test if codec changes configured bitrate.

Change VideoTrackTranscoderTests#PreserveBitrate to check the
bitrate passed in to the encoder rather than what comes out of the encoder.
Recent minimum quality work allows the encoder to "shape" the
MediaFormat if the quality is too low. This test triggered that.

Test: Transcoder unit test
Fixes: 184920307
Change-Id: Ia5edfc86ff1dff28d591cb5c011f26f9febd7a1d
parent 02ebd761
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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,
+2 −0
Original line number Diff line number Diff line
@@ -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>
@@ -101,6 +102,7 @@ private:
    uid_t mUid;
    uint64_t mInputFrameCount = 0;
    uint64_t mOutputFrameCount = 0;
    int32_t mConfiguredBitrate = 0;
};

}  // namespace android
+7 −7
Original line number Diff line number Diff line
@@ -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;
@@ -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*/);
@@ -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);
}