TRACKRENDERER_LEAVE;
}
+static GstCaps* ChooseDecoderCaps(GstCaps* inputCaps, GstCaps* parseCaps)
+{
+ auto GetMimeFunc = [](GstCaps* caps) -> std::string {
+ if (!caps) return {};
+ GstStructure* s = gst_caps_get_structure(caps, 0);
+ if (!s) return {};
+
+ return gst_structure_get_name(s);
+ };
+
+ auto inputMime = GetMimeFunc(inputCaps);
+ if (inputMime.empty()) {
+ TRACKRENDERER_ERROR("Invalid inputCaps, return null");
+ return nullptr;
+ }
+
+ auto parseMime = GetMimeFunc(parseCaps);
+ if (parseMime.empty()) {
+ TRACKRENDERER_ERROR("Invalid parseCaps, return inputCaps");
+ return inputCaps;
+ }
+
+ return (inputMime == parseMime) ? parseCaps : inputCaps;
+}
+
bool TrackRenderer::CreateVideoPipeline_(const Track* track) {
TRACKRENDERER_ENTER;
auto parse_caps =
gstguard::make_guard(pipeline_->GetSrcPadCaps(Elements::kParseVideo));
- if (!CreateDecoder_(track, parse_caps ? static_cast<GstCaps*>(parse_caps.get()) : caps.GetCaps_())) {
+ if (!CreateDecoder_(track, ChooseDecoderCaps(caps.GetCaps_(), static_cast<GstCaps*>(parse_caps.get())))) {
TRACKRENDERER_ERROR("Failed to make video decoder");
pipeline_->ElementRemove(Elements::kAppSrcVideo);
pipeline_->ElementRemove(Elements::kParseVideo);
auto parse_caps =
gstguard::make_guard(pipeline_->GetSrcPadCaps(Elements::kParseAudio));
- if (!CreateDecoder_(track, parse_caps ? static_cast<GstCaps*>(parse_caps.get()) : caps.GetCaps_())) {
+ if (!CreateDecoder_(track, ChooseDecoderCaps(caps.GetCaps_(), static_cast<GstCaps*>(parse_caps.get())))) {
TRACKRENDERER_ERROR("Failed to make audio decoder");
const ErrorType err = ErrorType::kNotSupportedAudioCodec;
eventlistener_->OnError(err);