3 * Copyright (c) 2011 Konstantin Shishkov
5 * This file is part of FFmpeg.
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "libavutil/intreadwrite.h"
30 typedef struct RV34ParseContext
{
35 static const int rv_to_av_frame_type
[4] = {
36 AV_PICTURE_TYPE_I
, AV_PICTURE_TYPE_I
, AV_PICTURE_TYPE_P
, AV_PICTURE_TYPE_B
,
39 static int rv34_parse(AVCodecParserContext
*s
,
40 AVCodecContext
*avctx
,
41 const uint8_t **poutbuf
, int *poutbuf_size
,
42 const uint8_t *buf
, int buf_size
)
44 RV34ParseContext
*pc
= s
->priv_data
;
47 if (buf_size
< 13 + *buf
* 8) {
49 *poutbuf_size
= buf_size
;
53 hdr
= AV_RB32(buf
+ 9 + *buf
* 8);
54 if (avctx
->codec_id
== AV_CODEC_ID_RV30
) {
55 type
= (hdr
>> 27) & 3;
56 pts
= (hdr
>> 7) & 0x1FFF;
58 type
= (hdr
>> 29) & 3;
59 pts
= (hdr
>> 6) & 0x1FFF;
62 if (type
!= 3 && s
->pts
!= AV_NOPTS_VALUE
) {
67 s
->pts
= pc
->key_dts
+ ((pts
- pc
->key_pts
) & 0x1FFF);
69 s
->pts
= pc
->key_dts
- ((pc
->key_pts
- pts
) & 0x1FFF);
71 s
->pict_type
= rv_to_av_frame_type
[type
];
74 *poutbuf_size
= buf_size
;
78 const AVCodecParser ff_rv34_parser
= {
79 .codec_ids
= { AV_CODEC_ID_RV30
, AV_CODEC_ID_RV40
},
80 .priv_data_size
= sizeof(RV34ParseContext
),
81 .parser_parse
= rv34_parse
,