AVStream *audio_st;
PacketQueue audioq;
int audio_hw_buf_size;
- uint8_t silence_buf[SDL_AUDIO_MIN_BUFFER_SIZE];
uint8_t *audio_buf;
uint8_t *audio_buf1;
unsigned int audio_buf_size; /* in bytes */
static void decoder_destroy(Decoder *d) {
av_packet_unref(&d->pkt);
+ avcodec_free_context(&d->avctx);
}
static void frame_queue_unref_item(Frame *vp)
static void stream_component_close(VideoState *is, int stream_index)
{
AVFormatContext *ic = is->ic;
- AVCodecContext *avctx;
+ AVCodecParameters *codecpar;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return;
- avctx = ic->streams[stream_index]->codec;
+ codecpar = ic->streams[stream_index]->codecpar;
- switch (avctx->codec_type) {
+ switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
decoder_abort(&is->auddec, &is->sampq);
SDL_CloseAudio();
}
ic->streams[stream_index]->discard = AVDISCARD_ALL;
- avcodec_close(avctx);
- switch (avctx->codec_type) {
+ switch (codecpar->codec_type) {
case AVMEDIA_TYPE_AUDIO:
is->audio_st = NULL;
is->audio_stream = -1;
aqsize / 1024,
vqsize / 1024,
sqsize,
- is->video_st ? is->video_st->codec->pts_correction_num_faulty_dts : 0,
- is->video_st ? is->video_st->codec->pts_correction_num_faulty_pts : 0);
+ is->video_st ? is->viddec.avctx->pts_correction_num_faulty_dts : 0,
+ is->video_st ? is->viddec.avctx->pts_correction_num_faulty_pts : 0);
fflush(stdout);
last_time = cur_time;
}
{
Frame *vp;
-#if defined(DEBUG_SYNC) && 0
+#if defined(DEBUG_SYNC)
printf("frame_type=%c pts=%0.3f\n",
av_get_picture_type_char(src_frame->pict_type), pts);
#endif
char buffersrc_args[256];
int ret;
AVFilterContext *filt_src = NULL, *filt_out = NULL, *last_filter = NULL;
- AVCodecContext *codec = is->video_st->codec;
+ AVCodecParameters *codecpar = is->video_st->codecpar;
AVRational fr = av_guess_frame_rate(is->ic, is->video_st, NULL);
AVDictionaryEntry *e = NULL;
"video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
frame->width, frame->height, frame->format,
is->video_st->time_base.num, is->video_st->time_base.den,
- codec->sample_aspect_ratio.num, FFMAX(codec->sample_aspect_ratio.den, 1));
+ codecpar->sample_aspect_ratio.num, FFMAX(codecpar->sample_aspect_ratio.den, 1));
if (fr.num && fr.den)
av_strlcatf(buffersrc_args, sizeof(buffersrc_args), ":frame_rate=%d/%d", fr.num, fr.den);
audio_size = audio_decode_frame(is);
if (audio_size < 0) {
/* if error, just output silence */
- is->audio_buf = is->silence_buf;
- is->audio_buf_size = sizeof(is->silence_buf) / is->audio_tgt.frame_size * is->audio_tgt.frame_size;
+ is->audio_buf = NULL;
+ is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE / is->audio_tgt.frame_size * is->audio_tgt.frame_size;
} else {
if (is->show_mode != SHOW_MODE_VIDEO)
update_sample_display(is, (int16_t *)is->audio_buf, audio_size);
len1 = is->audio_buf_size - is->audio_buf_index;
if (len1 > len)
len1 = len;
- if (!is->muted && is->audio_volume == SDL_MIX_MAXVOLUME)
+ if (!is->muted && is->audio_buf && is->audio_volume == SDL_MIX_MAXVOLUME)
memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
else {
- memset(stream, is->silence_buf[0], len1);
- if (!is->muted)
+ memset(stream, 0, len1);
+ if (!is->muted && is->audio_buf)
SDL_MixAudio(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1, is->audio_volume);
}
len -= len1;
AVCodecContext *avctx;
AVCodec *codec;
const char *forced_codec_name = NULL;
- AVDictionary *opts;
+ AVDictionary *opts = NULL;
AVDictionaryEntry *t = NULL;
int sample_rate, nb_channels;
int64_t channel_layout;
if (stream_index < 0 || stream_index >= ic->nb_streams)
return -1;
- avctx = ic->streams[stream_index]->codec;
+
+ avctx = avcodec_alloc_context3(NULL);
+ if (!avctx)
+ return AVERROR(ENOMEM);
+
+ ret = avcodec_parameters_to_context(avctx, ic->streams[stream_index]->codecpar);
+ if (ret < 0)
+ goto fail;
+ av_codec_set_pkt_timebase(avctx, ic->streams[stream_index]->time_base);
codec = avcodec_find_decoder(avctx->codec_id);
"No codec could be found with name '%s'\n", forced_codec_name);
else av_log(NULL, AV_LOG_WARNING,
"No codec could be found with id %d\n", avctx->codec_id);
- return -1;
+ ret = AVERROR(EINVAL);
+ goto fail;
}
avctx->codec_id = codec->id;
is->auddec.start_pts_tb = is->audio_st->time_base;
}
if ((ret = decoder_start(&is->auddec, audio_thread, is)) < 0)
- goto fail;
+ goto out;
SDL_PauseAudio(0);
break;
case AVMEDIA_TYPE_VIDEO:
decoder_init(&is->viddec, avctx, &is->videoq, is->continue_read_thread);
if ((ret = decoder_start(&is->viddec, video_thread, is)) < 0)
- goto fail;
+ goto out;
is->queue_attachments_req = 1;
break;
case AVMEDIA_TYPE_SUBTITLE:
decoder_init(&is->subdec, avctx, &is->subtitleq, is->continue_read_thread);
if ((ret = decoder_start(&is->subdec, subtitle_thread, is)) < 0)
- goto fail;
+ goto out;
break;
default:
break;
}
+ goto out;
fail:
+ avcodec_free_context(&avctx);
+out:
av_dict_free(&opts);
return ret;
for (i = 0; i < ic->nb_streams; i++) {
AVStream *st = ic->streams[i];
- enum AVMediaType type = st->codec->codec_type;
+ enum AVMediaType type = st->codecpar->codec_type;
st->discard = AVDISCARD_ALL;
if (wanted_stream_spec[type] && st_index[type] == -1)
if (avformat_match_stream_specifier(ic, st, wanted_stream_spec[type]) > 0)
is->show_mode = show_mode;
if (st_index[AVMEDIA_TYPE_VIDEO] >= 0) {
AVStream *st = ic->streams[st_index[AVMEDIA_TYPE_VIDEO]];
- AVCodecContext *avctx = st->codec;
+ AVCodecParameters *codecpar = st->codecpar;
AVRational sar = av_guess_sample_aspect_ratio(ic, st, NULL);
- if (avctx->width)
- set_default_window_size(avctx->width, avctx->height, sar);
+ if (codecpar->width)
+ set_default_window_size(codecpar->width, codecpar->height, sar);
}
/* open the streams */
if (stream_index == start_index)
return;
st = is->ic->streams[p ? p->stream_index[stream_index] : stream_index];
- if (st->codec->codec_type == codec_type) {
+ if (st->codecpar->codec_type == codec_type) {
/* check that parameters are OK */
switch (codec_type) {
case AVMEDIA_TYPE_AUDIO:
- if (st->codec->sample_rate != 0 &&
- st->codec->channels != 0)
+ if (st->codecpar->sample_rate != 0 &&
+ st->codecpar->channels != 0)
goto the_end;
break;
case AVMEDIA_TYPE_VIDEO: