| 116 | } |
| 117 | |
| 118 | void UpdateFormat(VideoBackendPlayer& player, VideoPlayerAndroid& playerAndroid, AMediaCodec* codec, AMediaFormat* format) |
| 119 | { |
| 120 | const bool isVideo = codec == playerAndroid.VideoCodec; |
| 121 | const bool isAudio = codec == playerAndroid.AudioCodec; |
| 122 | if (isVideo) |
| 123 | { |
| 124 | int32_t frameWidth = 0, frameHeight = 0, frameRate = 0, colorFormat = 0, stride = 0; |
| 125 | float frameRateF = 0.0f; |
| 126 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_WIDTH, &frameWidth); |
| 127 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_HEIGHT, &frameHeight); |
| 128 | if (AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_FRAME_RATE, &frameRate) && frameRate > 0) |
| 129 | player.FrameRate = (float)frameRate; |
| 130 | else if (AMediaFormat_getFloat(format, AMEDIAFORMAT_KEY_FRAME_RATE, &frameRateF) && frameRateF > 0) |
| 131 | player.FrameRate = frameRateF; |
| 132 | else |
| 133 | player.FrameRate = 60; |
| 134 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_STRIDE, &stride); |
| 135 | playerAndroid.VideoStride = stride; |
| 136 | player.Width = player.VideoFrameWidth = frameWidth; |
| 137 | player.Height = player.VideoFrameHeight = frameHeight; |
| 138 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, &colorFormat); |
| 139 | switch (colorFormat) |
| 140 | { |
| 141 | case COLOR_Format32bitABGR8888: |
| 142 | player.Format = PixelFormat::R8G8B8A8_UNorm; |
| 143 | break; |
| 144 | case COLOR_Format32bitBGRA8888: |
| 145 | player.Format = PixelFormat::B8G8R8A8_UNorm; |
| 146 | break; |
| 147 | case COLOR_FormatYUV420SemiPlanar: |
| 148 | player.Format = PixelFormat::NV12; |
| 149 | break; |
| 150 | case COLOR_FormatYUV422SemiPlanar: |
| 151 | player.Format = PixelFormat::YUY2; |
| 152 | break; |
| 153 | default: |
| 154 | player.Format = PixelFormat::Unknown; |
| 155 | LOG(Error, "[VideoBackendAndroid] Unsupported video color format {}", colorFormat); |
| 156 | break; |
| 157 | } |
| 158 | #if VIDEO_API_ANDROID_DEBUG |
| 159 | LOG(Info, "[VideoBackendAndroid] Video track: {}x{}, {}fps", player.Width, player.Height, player.FrameRate); |
| 160 | #endif |
| 161 | } |
| 162 | else if (isAudio) |
| 163 | { |
| 164 | int32_t sampleRate = 0, channelCount = 0, bitsPerSample = 0; |
| 165 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_SAMPLE_RATE, &sampleRate); |
| 166 | AMediaFormat_getInt32(format, AMEDIAFORMAT_KEY_CHANNEL_COUNT, &channelCount); |
| 167 | player.AudioInfo.SampleRate = sampleRate; |
| 168 | player.AudioInfo.NumChannels = channelCount; |
| 169 | if (AMediaFormat_getInt32(format, "bits-per-sample", &bitsPerSample) && bitsPerSample > 0) |
| 170 | player.AudioInfo.BitDepth = bitsPerSample; |
| 171 | else |
| 172 | player.AudioInfo.BitDepth = 16; |
| 173 | #if VIDEO_API_ANDROID_DEBUG |
| 174 | LOG(Info, "[VideoBackendAndroid] Audio track: {} channels, {} bits, {} kHz sample rate", player.AudioInfo.NumChannels, player.AudioInfo.BitDepth, player.AudioInfo.SampleRate / 1000); |
| 175 | #endif |
no outgoing calls
no test coverage detected