mirror of https://github.com/procxx/kepka.git
Fail streaming if no codec for a stream.
This commit is contained in:
parent
aade3d4f27
commit
518d1da736
|
@ -107,7 +107,7 @@ Stream File::Context::initStream(
|
||||||
nullptr,
|
nullptr,
|
||||||
0);
|
0);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
return {};
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto info = format->streams[index];
|
const auto info = format->streams[index];
|
||||||
|
@ -117,25 +117,27 @@ Stream File::Context::initStream(
|
||||||
} else if (type == AVMEDIA_TYPE_AUDIO) {
|
} else if (type == AVMEDIA_TYPE_AUDIO) {
|
||||||
result.frequency = info->codecpar->sample_rate;
|
result.frequency = info->codecpar->sample_rate;
|
||||||
if (!result.frequency) {
|
if (!result.frequency) {
|
||||||
return {};
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.codec = MakeCodecPointer(info);
|
result.codec = MakeCodecPointer(info);
|
||||||
if (!result.codec) {
|
if (!result.codec) {
|
||||||
return {};
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.frame = MakeFramePointer();
|
result.frame = MakeFramePointer();
|
||||||
if (!result.frame) {
|
if (!result.frame) {
|
||||||
return {};
|
result.codec = nullptr;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
result.timeBase = info->time_base;
|
result.timeBase = info->time_base;
|
||||||
result.duration = (info->duration != AV_NOPTS_VALUE)
|
result.duration = (info->duration != AV_NOPTS_VALUE)
|
||||||
? PtsToTime(info->duration, result.timeBase)
|
? PtsToTime(info->duration, result.timeBase)
|
||||||
: PtsToTime(format->duration, kUniversalTimeBase);
|
: PtsToTime(format->duration, kUniversalTimeBase);
|
||||||
if (result.duration == kTimeUnknown || !result.duration) {
|
if (result.duration == kTimeUnknown || !result.duration) {
|
||||||
return {};
|
result.codec = nullptr;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
// We want duration to be greater than any valid frame position.
|
// We want duration to be greater than any valid frame position.
|
||||||
// That way we can handle looping by advancing position by n * duration.
|
// That way we can handle looping by advancing position by n * duration.
|
||||||
|
|
|
@ -214,7 +214,13 @@ bool Player::fileReady(Stream &&video, Stream &&audio) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const auto mode = _options.mode;
|
const auto mode = _options.mode;
|
||||||
if (audio.codec && (mode == Mode::Audio || mode == Mode::Both)) {
|
if (mode != Mode::Audio && mode != Mode::Both) {
|
||||||
|
audio = Stream();
|
||||||
|
}
|
||||||
|
if (mode != Mode::Video && mode != Mode::Both) {
|
||||||
|
video = Stream();
|
||||||
|
}
|
||||||
|
if (audio.codec) {
|
||||||
if (_options.audioId.audio() != nullptr) {
|
if (_options.audioId.audio() != nullptr) {
|
||||||
_audioId = AudioMsgId(
|
_audioId = AudioMsgId(
|
||||||
_options.audioId.audio(),
|
_options.audioId.audio(),
|
||||||
|
@ -229,16 +235,26 @@ bool Player::fileReady(Stream &&video, Stream &&audio) {
|
||||||
_audioId,
|
_audioId,
|
||||||
ready,
|
ready,
|
||||||
error(_audio));
|
error(_audio));
|
||||||
|
} else if (audio.index >= 0) {
|
||||||
|
LOG(("Streaming Error: No codec for audio stream %1, mode %2."
|
||||||
|
).arg(audio.index
|
||||||
|
).arg(int(mode)));
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
_audioId = AudioMsgId();
|
_audioId = AudioMsgId();
|
||||||
}
|
}
|
||||||
if (video.codec && (mode == Mode::Video || mode == Mode::Both)) {
|
if (video.codec) {
|
||||||
_video = std::make_unique<VideoTrack>(
|
_video = std::make_unique<VideoTrack>(
|
||||||
_options,
|
_options,
|
||||||
std::move(video),
|
std::move(video),
|
||||||
_audioId,
|
_audioId,
|
||||||
ready,
|
ready,
|
||||||
error(_video));
|
error(_video));
|
||||||
|
} else if (video.index >= 0) {
|
||||||
|
LOG(("Streaming Error: No codec for video stream %1, mode %2."
|
||||||
|
).arg(audio.index
|
||||||
|
).arg(int(mode)));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if ((mode == Mode::Audio && !_audio)
|
if ((mode == Mode::Audio && !_audio)
|
||||||
|| (mode == Mode::Video && !_video)
|
|| (mode == Mode::Video && !_video)
|
||||||
|
|
Loading…
Reference in New Issue