You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-10 06:10:52 +02:00
Merge remote-tracking branch 'qatar/master'
* qatar/master: asfdec: cosmetics, reformat ff_asf_parse_packet() g.723.1: add missing CODEC_CAP_DR1 avconv: remove now unneeded calls to avcodec_get_frame_defaults(). lavc: initialize output AVFrame before decoding. Conflicts: libavformat/asfdec.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
4
ffmpeg.c
4
ffmpeg.c
@@ -1422,8 +1422,6 @@ static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output)
|
|||||||
|
|
||||||
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
|
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
else
|
|
||||||
avcodec_get_frame_defaults(ist->decoded_frame);
|
|
||||||
decoded_frame = ist->decoded_frame;
|
decoded_frame = ist->decoded_frame;
|
||||||
|
|
||||||
update_benchmark(NULL);
|
update_benchmark(NULL);
|
||||||
@@ -1545,8 +1543,6 @@ static int decode_video(InputStream *ist, AVPacket *pkt, int *got_output)
|
|||||||
|
|
||||||
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
|
if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame()))
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
else
|
|
||||||
avcodec_get_frame_defaults(ist->decoded_frame);
|
|
||||||
decoded_frame = ist->decoded_frame;
|
decoded_frame = ist->decoded_frame;
|
||||||
pkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
|
pkt->dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ist->st->time_base);
|
||||||
|
|
||||||
|
@@ -1643,6 +1643,8 @@ int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *pi
|
|||||||
if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
|
if ((avctx->coded_width || avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx))
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
|
avcodec_get_frame_defaults(picture);
|
||||||
|
|
||||||
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
|
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type & FF_THREAD_FRAME)) {
|
||||||
int did_split = av_packet_split_side_data(&tmp);
|
int did_split = av_packet_split_side_data(&tmp);
|
||||||
apply_param_change(avctx, &tmp);
|
apply_param_change(avctx, &tmp);
|
||||||
@@ -1759,6 +1761,8 @@ int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx,
|
|||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avcodec_get_frame_defaults(frame);
|
||||||
|
|
||||||
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
|
if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) {
|
||||||
uint8_t *side;
|
uint8_t *side;
|
||||||
int side_size;
|
int side_size;
|
||||||
|
@@ -1008,13 +1008,14 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
ASFStream *asf_st = 0;
|
ASFStream *asf_st = 0;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int ret;
|
int ret;
|
||||||
if(url_feof(pb))
|
if (url_feof(pb))
|
||||||
return AVERROR_EOF;
|
return AVERROR_EOF;
|
||||||
if (asf->packet_size_left < FRAME_HEADER_SIZE
|
|
||||||
|| asf->packet_segments < 1) {
|
if (asf->packet_size_left < FRAME_HEADER_SIZE ||
|
||||||
//asf->packet_size_left <= asf->packet_padsize) {
|
asf->packet_segments < 1) {
|
||||||
int ret = asf->packet_size_left + asf->packet_padsize;
|
int ret = asf->packet_size_left + asf->packet_padsize;
|
||||||
assert(ret>=0);
|
|
||||||
|
assert(ret >= 0);
|
||||||
/* fail safe */
|
/* fail safe */
|
||||||
avio_skip(pb, ret);
|
avio_skip(pb, ret);
|
||||||
|
|
||||||
@@ -1025,19 +1026,19 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (asf->packet_time_start == 0) {
|
if (asf->packet_time_start == 0) {
|
||||||
if(asf_read_frame_header(s, pb) < 0){
|
if (asf_read_frame_header(s, pb) < 0) {
|
||||||
asf->packet_segments= 0;
|
asf->packet_segments = 0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (asf->stream_index < 0
|
if (asf->stream_index < 0 ||
|
||||||
|| s->streams[asf->stream_index]->discard >= AVDISCARD_ALL
|
s->streams[asf->stream_index]->discard >= AVDISCARD_ALL ||
|
||||||
|| (!asf->packet_key_frame && s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)
|
(!asf->packet_key_frame &&
|
||||||
) {
|
s->streams[asf->stream_index]->discard >= AVDISCARD_NONKEY)) {
|
||||||
asf->packet_time_start = 0;
|
asf->packet_time_start = 0;
|
||||||
/* unhandled packet (should not happen) */
|
/* unhandled packet (should not happen) */
|
||||||
avio_skip(pb, asf->packet_frag_size);
|
avio_skip(pb, asf->packet_frag_size);
|
||||||
asf->packet_size_left -= asf->packet_frag_size;
|
asf->packet_size_left -= asf->packet_frag_size;
|
||||||
if(asf->stream_index < 0)
|
if (asf->stream_index < 0)
|
||||||
av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
|
av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1048,12 +1049,11 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
if (asf->packet_replic_size == 1) {
|
if (asf->packet_replic_size == 1) {
|
||||||
// frag_offset is here used as the beginning timestamp
|
// frag_offset is here used as the beginning timestamp
|
||||||
asf->packet_frag_timestamp = asf->packet_time_start;
|
asf->packet_frag_timestamp = asf->packet_time_start;
|
||||||
asf->packet_time_start += asf->packet_time_delta;
|
asf->packet_time_start += asf->packet_time_delta;
|
||||||
asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
|
asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb);
|
||||||
asf->packet_size_left--;
|
asf->packet_size_left--;
|
||||||
asf->packet_multi_size--;
|
asf->packet_multi_size--;
|
||||||
if (asf->packet_multi_size < asf->packet_obj_size)
|
if (asf->packet_multi_size < asf->packet_obj_size) {
|
||||||
{
|
|
||||||
asf->packet_time_start = 0;
|
asf->packet_time_start = 0;
|
||||||
avio_skip(pb, asf->packet_multi_size);
|
avio_skip(pb, asf->packet_multi_size);
|
||||||
asf->packet_size_left -= asf->packet_multi_size;
|
asf->packet_size_left -= asf->packet_multi_size;
|
||||||
@@ -1061,29 +1061,30 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
}
|
}
|
||||||
asf->packet_multi_size -= asf->packet_obj_size;
|
asf->packet_multi_size -= asf->packet_obj_size;
|
||||||
}
|
}
|
||||||
if( /*asf->packet_frag_size == asf->packet_obj_size*/
|
if (asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size &&
|
||||||
asf_st->frag_offset + asf->packet_frag_size <= asf_st->pkt.size
|
asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size) {
|
||||||
&& asf_st->frag_offset + asf->packet_frag_size > asf->packet_obj_size){
|
|
||||||
av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
|
av_log(s, AV_LOG_INFO, "ignoring invalid packet_obj_size (%d %d %d %d)\n",
|
||||||
asf_st->frag_offset, asf->packet_frag_size,
|
asf_st->frag_offset, asf->packet_frag_size,
|
||||||
asf->packet_obj_size, asf_st->pkt.size);
|
asf->packet_obj_size, asf_st->pkt.size);
|
||||||
asf->packet_obj_size= asf_st->pkt.size;
|
asf->packet_obj_size = asf_st->pkt.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( asf_st->pkt.size != asf->packet_obj_size
|
if (asf_st->pkt.size != asf->packet_obj_size ||
|
||||||
|| asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) { //FIXME is this condition sufficient?
|
//FIXME is this condition sufficient?
|
||||||
if(asf_st->pkt.data){
|
asf_st->frag_offset + asf->packet_frag_size > asf_st->pkt.size) {
|
||||||
av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, new %d\n", asf_st->pkt.size, asf->packet_obj_size);
|
if (asf_st->pkt.data) {
|
||||||
|
av_log(s, AV_LOG_INFO, "freeing incomplete packet size %d, "
|
||||||
|
"new %d\n", asf_st->pkt.size, asf->packet_obj_size);
|
||||||
asf_st->frag_offset = 0;
|
asf_st->frag_offset = 0;
|
||||||
av_free_packet(&asf_st->pkt);
|
av_free_packet(&asf_st->pkt);
|
||||||
}
|
}
|
||||||
/* new packet */
|
/* new packet */
|
||||||
av_new_packet(&asf_st->pkt, asf->packet_obj_size);
|
av_new_packet(&asf_st->pkt, asf->packet_obj_size);
|
||||||
asf_st->seq = asf->packet_seq;
|
asf_st->seq = asf->packet_seq;
|
||||||
asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
|
asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll;
|
||||||
asf_st->pkt.stream_index = asf->stream_index;
|
asf_st->pkt.stream_index = asf->stream_index;
|
||||||
asf_st->pkt.pos =
|
asf_st->pkt.pos = asf_st->packet_pos = asf->packet_pos;
|
||||||
asf_st->packet_pos= asf->packet_pos;
|
|
||||||
if (asf_st->pkt.data && asf_st->palette_changed) {
|
if (asf_st->pkt.data && asf_st->palette_changed) {
|
||||||
uint8_t *pal;
|
uint8_t *pal;
|
||||||
pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE,
|
pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE,
|
||||||
@@ -1114,18 +1115,19 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
if (asf->packet_size_left < 0)
|
if (asf->packet_size_left < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if( asf->packet_frag_offset >= asf_st->pkt.size
|
if (asf->packet_frag_offset >= asf_st->pkt.size ||
|
||||||
|| asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset){
|
asf->packet_frag_size > asf_st->pkt.size - asf->packet_frag_offset) {
|
||||||
av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
|
av_log(s, AV_LOG_ERROR, "packet fragment position invalid %u,%u not in %u\n",
|
||||||
asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
|
asf->packet_frag_offset, asf->packet_frag_size, asf_st->pkt.size);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
|
ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset,
|
||||||
asf->packet_frag_size);
|
asf->packet_frag_size);
|
||||||
if (ret != asf->packet_frag_size) {
|
if (ret != asf->packet_frag_size) {
|
||||||
if (ret < 0 || asf->packet_frag_offset + ret == 0)
|
if (ret < 0 || asf->packet_frag_offset + ret == 0)
|
||||||
return ret < 0 ? ret : AVERROR_EOF;
|
return ret < 0 ? ret : AVERROR_EOF;
|
||||||
|
|
||||||
if (asf_st->ds_span > 1) {
|
if (asf_st->ds_span > 1) {
|
||||||
// scrambling, we can either drop it completely or fill the remainder
|
// scrambling, we can either drop it completely or fill the remainder
|
||||||
// TODO: should we fill the whole packet instead of just the current
|
// TODO: should we fill the whole packet instead of just the current
|
||||||
@@ -1133,9 +1135,10 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
|
memset(asf_st->pkt.data + asf->packet_frag_offset + ret, 0,
|
||||||
asf->packet_frag_size - ret);
|
asf->packet_frag_size - ret);
|
||||||
ret = asf->packet_frag_size;
|
ret = asf->packet_frag_size;
|
||||||
} else
|
} else {
|
||||||
// no scrambling, so we can return partial packets
|
// no scrambling, so we can return partial packets
|
||||||
av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
|
av_shrink_packet(&asf_st->pkt, asf->packet_frag_offset + ret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (s->key && s->keylen == 20)
|
if (s->key && s->keylen == 20)
|
||||||
ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
|
ff_asfcrypt_dec(s->key, asf_st->pkt.data + asf->packet_frag_offset,
|
||||||
@@ -1144,11 +1147,11 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
/* test if whole packet is read */
|
/* test if whole packet is read */
|
||||||
if (asf_st->frag_offset == asf_st->pkt.size) {
|
if (asf_st->frag_offset == asf_st->pkt.size) {
|
||||||
//workaround for macroshit radio DVR-MS files
|
//workaround for macroshit radio DVR-MS files
|
||||||
if( s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO
|
if (s->streams[asf->stream_index]->codec->codec_id == AV_CODEC_ID_MPEG2VIDEO &&
|
||||||
&& asf_st->pkt.size > 100){
|
asf_st->pkt.size > 100) {
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
|
for (i = 0; i < asf_st->pkt.size && !asf_st->pkt.data[i]; i++);
|
||||||
if(i == asf_st->pkt.size){
|
if (i == asf_st->pkt.size) {
|
||||||
av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
|
av_log(s, AV_LOG_DEBUG, "discarding ms fart\n");
|
||||||
asf_st->frag_offset = 0;
|
asf_st->frag_offset = 0;
|
||||||
av_free_packet(&asf_st->pkt);
|
av_free_packet(&asf_st->pkt);
|
||||||
@@ -1158,37 +1161,39 @@ static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pk
|
|||||||
|
|
||||||
/* return packet */
|
/* return packet */
|
||||||
if (asf_st->ds_span > 1) {
|
if (asf_st->ds_span > 1) {
|
||||||
if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span){
|
if(asf_st->pkt.size != asf_st->ds_packet_size * asf_st->ds_span) {
|
||||||
av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * ds_span (%d %d %d)\n", asf_st->pkt.size, asf_st->ds_packet_size, asf_st->ds_span);
|
av_log(s, AV_LOG_ERROR, "pkt.size != ds_packet_size * "
|
||||||
}else{
|
"ds_span (%d %d %d)\n", asf_st->pkt.size,
|
||||||
/* packet descrambling */
|
asf_st->ds_packet_size, asf_st->ds_span);
|
||||||
uint8_t *newdata = av_malloc(asf_st->pkt.size + FF_INPUT_BUFFER_PADDING_SIZE);
|
} else {
|
||||||
if (newdata) {
|
/* packet descrambling */
|
||||||
int offset = 0;
|
uint8_t *newdata = av_malloc(asf_st->pkt.size + FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
memset(newdata + asf_st->pkt.size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
if (newdata) {
|
||||||
while (offset < asf_st->pkt.size) {
|
int offset = 0;
|
||||||
int off = offset / asf_st->ds_chunk_size;
|
memset(newdata + asf_st->pkt.size, 0, FF_INPUT_BUFFER_PADDING_SIZE);
|
||||||
int row = off / asf_st->ds_span;
|
while (offset < asf_st->pkt.size) {
|
||||||
int col = off % asf_st->ds_span;
|
int off = offset / asf_st->ds_chunk_size;
|
||||||
int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
|
int row = off / asf_st->ds_span;
|
||||||
assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
|
int col = off % asf_st->ds_span;
|
||||||
assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
|
int idx = row + col * asf_st->ds_packet_size / asf_st->ds_chunk_size;
|
||||||
memcpy(newdata + offset,
|
assert(offset + asf_st->ds_chunk_size <= asf_st->pkt.size);
|
||||||
asf_st->pkt.data + idx * asf_st->ds_chunk_size,
|
assert(idx+1 <= asf_st->pkt.size / asf_st->ds_chunk_size);
|
||||||
asf_st->ds_chunk_size);
|
memcpy(newdata + offset,
|
||||||
offset += asf_st->ds_chunk_size;
|
asf_st->pkt.data + idx * asf_st->ds_chunk_size,
|
||||||
|
asf_st->ds_chunk_size);
|
||||||
|
offset += asf_st->ds_chunk_size;
|
||||||
|
}
|
||||||
|
av_free(asf_st->pkt.data);
|
||||||
|
asf_st->pkt.data = newdata;
|
||||||
}
|
}
|
||||||
av_free(asf_st->pkt.data);
|
|
||||||
asf_st->pkt.data = newdata;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
asf_st->frag_offset = 0;
|
asf_st->frag_offset = 0;
|
||||||
*pkt= asf_st->pkt;
|
*pkt = asf_st->pkt;
|
||||||
asf_st->pkt.size = 0;
|
asf_st->pkt.size = 0;
|
||||||
asf_st->pkt.data = 0;
|
asf_st->pkt.data = 0;
|
||||||
asf_st->pkt.side_data_elems = 0;
|
asf_st->pkt.side_data_elems = 0;
|
||||||
asf_st->pkt.side_data = NULL;
|
asf_st->pkt.side_data = NULL;
|
||||||
break; // packet completed
|
break; // packet completed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user