a0b0d753 |
/*
* FLV decoding. |
ff4d1aa8 |
* |
a0b0d753 |
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
|
7ffe76e5 |
#include "libavutil/imgutils.h" |
a0b0d753 |
|
ff4d1aa8 |
#include "flv.h"
#include "h263.h"
#include "mpegvideo.h" |
378a0008 |
#include "mpegvideodata.h" |
ff4d1aa8 |
|
a0b0d753 |
int ff_flv_decode_picture_header(MpegEncContext *s)
{
int format, width, height;
/* picture header */
if (get_bits_long(&s->gb, 17) != 1) {
av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n"); |
ac006d29 |
return AVERROR_INVALIDDATA; |
a0b0d753 |
}
format = get_bits(&s->gb, 5);
if (format != 0 && format != 1) {
av_log(s->avctx, AV_LOG_ERROR, "Bad picture format\n"); |
ac006d29 |
return AVERROR_INVALIDDATA; |
a0b0d753 |
} |
c6b42e85 |
s->h263_flv = format + 1; |
a0b0d753 |
s->picture_number = get_bits(&s->gb, 8); /* picture timestamp */ |
c6b42e85 |
format = get_bits(&s->gb, 3); |
a0b0d753 |
switch (format) {
case 0: |
c6b42e85 |
width = get_bits(&s->gb, 8); |
a0b0d753 |
height = get_bits(&s->gb, 8);
break;
case 1: |
c6b42e85 |
width = get_bits(&s->gb, 16); |
a0b0d753 |
height = get_bits(&s->gb, 16);
break;
case 2: |
c6b42e85 |
width = 352; |
a0b0d753 |
height = 288;
break;
case 3: |
c6b42e85 |
width = 176; |
a0b0d753 |
height = 144;
break;
case 4: |
c6b42e85 |
width = 128; |
a0b0d753 |
height = 96;
break;
case 5: |
c6b42e85 |
width = 320; |
a0b0d753 |
height = 240;
break;
case 6: |
c6b42e85 |
width = 160; |
a0b0d753 |
height = 120;
break;
default:
width = height = 0;
break;
} |
c6b42e85 |
if (av_image_check_size(width, height, 0, s->avctx)) |
ac006d29 |
return AVERROR(EINVAL); |
c6b42e85 |
s->width = width; |
a0b0d753 |
s->height = height;
|
ce5e49b0 |
s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2); |
ba0c8981 |
s->droppable = s->pict_type > AV_PICTURE_TYPE_P;
if (s->droppable) |
ce5e49b0 |
s->pict_type = AV_PICTURE_TYPE_P; |
a0b0d753 |
skip_bits1(&s->gb); /* deblocking flag */ |
c6b42e85 |
s->chroma_qscale = s->qscale = get_bits(&s->gb, 5); |
a0b0d753 |
s->h263_plus = 0;
|
c6b42e85 |
s->unrestricted_mv = 1; |
a0b0d753 |
s->h263_long_vectors = 0;
/* PEI */ |
9c284a8e |
if (skip_1stop_8data_bits(&s->gb) < 0)
return AVERROR_INVALIDDATA; |
3ea5beab |
|
a0b0d753 |
s->f_code = 1;
|
7495186f |
if (s->ehc_mode)
s->avctx->sample_aspect_ratio= (AVRational){1,2};
|
c6b42e85 |
if (s->avctx->debug & FF_DEBUG_PICT_INFO) { |
a0b0d753 |
av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", |
ba0c8981 |
s->droppable ? 'D' : av_get_picture_type_char(s->pict_type),
s->h263_flv - 1, s->qscale, s->picture_number); |
a0b0d753 |
}
|
c6b42e85 |
s->y_dc_scale_table = s->c_dc_scale_table = ff_mpeg1_dc_scale_table; |
a0b0d753 |
return 0;
}
|
e7e2df27 |
AVCodec ff_flv_decoder = { |
ec6402b7 |
.name = "flv", |
b2bed932 |
.long_name = NULL_IF_CONFIG_SMALL("FLV / Sorenson Spark / Sorenson H.263 (Flash Video)"), |
ec6402b7 |
.type = AVMEDIA_TYPE_VIDEO, |
36ef5369 |
.id = AV_CODEC_ID_FLV1, |
ec6402b7 |
.priv_data_size = sizeof(MpegEncContext),
.init = ff_h263_decode_init,
.close = ff_h263_decode_end,
.decode = ff_h263_decode_frame, |
def97856 |
.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1, |
cde007dc |
.caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, |
5e50a572 |
.max_lowres = 3, |
ff4d1aa8 |
.pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P,
AV_PIX_FMT_NONE }, |
a0b0d753 |
}; |