1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| AMediaFormat* MediaCodecDecoderImpl::CreateMediaFormat( const VideoInfo& video_info, const ExtraData& extra_data) { std::string mime_type = CodecTypeConvert<CodecType, std::string>(video_info.codec_type);
AMediaFormat* format = AMediaFormat_new(); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, video_info.width); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, video_info.height); AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, mime_type.c_str()); AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, pix_fmt); switch (video_info.codec_type) { case CodecType::CODEC_TYPE_H264: { auto* avc_ps_ = new avc::ParamSets(); himawari::avc::ParseExtraDataToParamSet(extra_data, *avc_ps_); if (avc_ps_->sps_list.empty() || avc_ps_->pps_list.empty()) { return nullptr; } AMediaFormat_setBuffer(format, "csd-0", avc_ps_->sps_list[0].data, avc_ps_->sps_list[0].data_size); AMediaFormat_setBuffer(format, "csd-1", avc_ps_->pps_list[0].data, avc_ps_->pps_list[0].data_size); delete avc_ps_; } break; case CodecType::CODEC_TYPE_H265: { auto* hevc_ps = new hevc::ParamSets(); himawari::hevc::ParseExtraDataToParamSet(extra_data, *hevc_ps); if (hevc_ps->vps_list.empty() || hevc_ps->sps_list.empty() || hevc_ps->pps_list.empty()) { return nullptr; } AMediaFormat_setBuffer(format, "csd-0", hevc_ps->vps_list[0].data, hevc_ps->vps_list[0].data_size); AMediaFormat_setBuffer(format, "csd-1", hevc_ps->sps_list[0].data, hevc_ps->sps_list[0].data_size); AMediaFormat_setBuffer(format, "csd-2", hevc_ps->pps_list[0].data, hevc_ps->pps_list[0].data_size); delete hevc_ps; } break; default: return nullptr; } return format; }
|