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

Commit 72fedd60 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Transcoder: Add default codec operating rate."

parents e7350052 7a127b2a
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -73,4 +73,18 @@ void CopyFormatEntries(AMediaFormat* from, AMediaFormat* to, const EntryCopier*
        }
    }
}

#define DEFINE_SET_DEFAULT_FORMAT_VALUE_FUNC(_type, _typeName)                                  \
    bool SetDefaultFormatValue##_typeName(const char* key, AMediaFormat* format, _type value) { \
        _type tmp;                                                                              \
        if (!AMediaFormat_get##_typeName(format, key, &tmp)) {                                  \
            AMediaFormat_set##_typeName(format, key, value);                                    \
            return true;                                                                        \
        }                                                                                       \
        return false;                                                                           \
    }

DEFINE_SET_DEFAULT_FORMAT_VALUE_FUNC(float, Float);
DEFINE_SET_DEFAULT_FORMAT_VALUE_FUNC(int32_t, Int32);

}  // namespace AMediaFormatUtils
 No newline at end of file
+17 −10
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include <media/VideoTrackTranscoder.h>
#include <utils/AndroidThreads.h>

using namespace AMediaFormatUtils;

namespace android {

// Check that the codec sample flags have the expected NDK meaning.
@@ -36,6 +38,12 @@ static_assert(SAMPLE_FLAG_PARTIAL_FRAME == AMEDIACODEC_BUFFER_FLAG_PARTIAL_FRAME
static constexpr int32_t kColorFormatSurface = 0x7f000789;
// Default key frame interval in seconds.
static constexpr float kDefaultKeyFrameIntervalSeconds = 1.0f;
// Default codec operating rate.
static constexpr int32_t kDefaultCodecOperatingRate = 240;
// Default codec priority.
static constexpr int32_t kDefaultCodecPriority = 1;
// Default bitrate, in case source estimation fails.
static constexpr int32_t kDefaultBitrateMbps = 10 * 1000 * 1000;

template <typename T>
void VideoTrackTranscoder::BlockingQueue<T>::push(T const& value, bool front) {
@@ -176,8 +184,6 @@ VideoTrackTranscoder::~VideoTrackTranscoder() {
// Creates and configures the codecs.
media_status_t VideoTrackTranscoder::configureDestinationFormat(
        const std::shared_ptr<AMediaFormat>& destinationFormat) {
    static constexpr int32_t kDefaultBitrateMbps = 10 * 1000 * 1000;

    media_status_t status = AMEDIA_OK;

    if (destinationFormat == nullptr) {
@@ -203,11 +209,12 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat(
        AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_BIT_RATE, bitrate);
    }

    float tmp;
    if (!AMediaFormat_getFloat(encoderFormat, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, &tmp)) {
        AMediaFormat_setFloat(encoderFormat, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL,
    SetDefaultFormatValueFloat(AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, encoderFormat,
                               kDefaultKeyFrameIntervalSeconds);
    }
    SetDefaultFormatValueInt32(AMEDIAFORMAT_KEY_OPERATING_RATE, encoderFormat,
                               kDefaultCodecOperatingRate);
    SetDefaultFormatValueInt32(AMEDIAFORMAT_KEY_PRIORITY, encoderFormat, kDefaultCodecPriority);

    AMediaFormat_setInt32(encoderFormat, AMEDIAFORMAT_KEY_COLOR_FORMAT, kColorFormatSurface);

    // Always encode without rotation. The rotation degree will be transferred directly to
@@ -271,13 +278,13 @@ media_status_t VideoTrackTranscoder::configureDestinationFormat(
    AMediaFormat_setInt32(decoderFormat.get(), TBD_AMEDIACODEC_PARAMETER_KEY_ALLOW_FRAME_DROP, 0);

    // Copy over configurations that apply to both encoder and decoder.
    static const AMediaFormatUtils::EntryCopier kEncoderEntriesToCopy[] = {
    static const 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]);
    AMediaFormatUtils::CopyFormatEntries(mDestinationFormat.get(), decoderFormat.get(),
                                         kEncoderEntriesToCopy, entryCount);
    CopyFormatEntries(mDestinationFormat.get(), decoderFormat.get(), kEncoderEntriesToCopy,
                      entryCount);

    status = AMediaCodec_configure(mDecoder, decoderFormat.get(), mSurface, NULL /* crypto */,
                                   0 /* flags */);
+3 −0
Original line number Diff line number Diff line
@@ -78,5 +78,8 @@ bool CopyFormatEntryFloat(const char* key, AMediaFormat* from, AMediaFormat* to)
void CopyFormatEntries(AMediaFormat* from, AMediaFormat* to, const EntryCopier* entries,
                       size_t entryCount);

bool SetDefaultFormatValueFloat(const char* key, AMediaFormat* format, float value);
bool SetDefaultFormatValueInt32(const char* key, AMediaFormat* format, int32_t value);

}  // namespace AMediaFormatUtils
#endif  // ANDROID_MEDIA_TRANSCODING_NDK_COMMON_H