mirror of
https://github.com/telegramdesktop/tdesktop
synced 2024-12-26 00:12:25 +00:00
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,
|
||||
0);
|
||||
if (index < 0) {
|
||||
return {};
|
||||
return result;
|
||||
}
|
||||
|
||||
const auto info = format->streams[index];
|
||||
@ -117,25 +117,27 @@ Stream File::Context::initStream(
|
||||
} else if (type == AVMEDIA_TYPE_AUDIO) {
|
||||
result.frequency = info->codecpar->sample_rate;
|
||||
if (!result.frequency) {
|
||||
return {};
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result.codec = MakeCodecPointer(info);
|
||||
if (!result.codec) {
|
||||
return {};
|
||||
return result;
|
||||
}
|
||||
|
||||
result.frame = MakeFramePointer();
|
||||
if (!result.frame) {
|
||||
return {};
|
||||
result.codec = nullptr;
|
||||
return result;
|
||||
}
|
||||
result.timeBase = info->time_base;
|
||||
result.duration = (info->duration != AV_NOPTS_VALUE)
|
||||
? PtsToTime(info->duration, result.timeBase)
|
||||
: PtsToTime(format->duration, kUniversalTimeBase);
|
||||
if (result.duration == kTimeUnknown || !result.duration) {
|
||||
return {};
|
||||
result.codec = nullptr;
|
||||
return result;
|
||||
}
|
||||
// We want duration to be greater than any valid frame position.
|
||||
// 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;
|
||||
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) {
|
||||
_audioId = AudioMsgId(
|
||||
_options.audioId.audio(),
|
||||
@ -229,16 +235,26 @@ bool Player::fileReady(Stream &&video, Stream &&audio) {
|
||||
_audioId,
|
||||
ready,
|
||||
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 {
|
||||
_audioId = AudioMsgId();
|
||||
}
|
||||
if (video.codec && (mode == Mode::Video || mode == Mode::Both)) {
|
||||
if (video.codec) {
|
||||
_video = std::make_unique<VideoTrack>(
|
||||
_options,
|
||||
std::move(video),
|
||||
_audioId,
|
||||
ready,
|
||||
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)
|
||||
|| (mode == Mode::Video && !_video)
|
||||
|
Loading…
Reference in New Issue
Block a user