3 * Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
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 "dnxhddata.h"
29 #include "parser_internal.h"
38 static int dnxhd_find_frame_end(DNXHDParserContext
*dctx
,
39 const uint8_t *buf
, int buf_size
)
41 ParseContext
*pc
= &dctx
->pc
;
42 uint64_t state
= pc
->state64
;
43 int pic_found
= pc
->frame_start_found
;
47 for (i
= 0; i
< buf_size
; i
++) {
48 state
= (state
<< 8) | buf
[i
];
49 if (ff_dnxhd_check_header_prefix(state
& 0xffffffffff00LL
) != 0) {
59 if (pic_found
&& !dctx
->remaining
) {
60 if (!buf_size
) /* EOF considered as end of frame */
62 for (; i
< buf_size
; i
++) {
64 state
= (state
<< 8) | buf
[i
];
66 if (dctx
->cur_byte
== 24) {
67 dctx
->h
= (state
>> 32) & 0xFFFF;
68 } else if (dctx
->cur_byte
== 26) {
69 dctx
->w
= (state
>> 32) & 0xFFFF;
70 } else if (dctx
->cur_byte
== 42) {
71 int cid
= (state
>> 32) & 0xFFFFFFFF;
77 remaining
= ff_dnxhd_get_frame_size(cid
);
79 remaining
= ff_dnxhd_get_hr_frame_size(cid
, dctx
->w
, dctx
->h
);
84 dctx
->remaining
= remaining
;
85 if (buf_size
>= dctx
->remaining
) {
86 pc
->frame_start_found
= 0;
92 dctx
->remaining
-= buf_size
;
93 // Update variables for correctness, they are currently not used beyond here
95 dctx
->cur_byte
+= buf_size
- i
;
100 } else if (pic_found
) {
101 if (dctx
->remaining
> buf_size
) {
102 dctx
->remaining
-= buf_size
;
104 int remaining
= dctx
->remaining
;
106 pc
->frame_start_found
= 0;
113 pc
->frame_start_found
= pic_found
;
115 return END_NOT_FOUND
;
118 static int dnxhd_parse(AVCodecParserContext
*s
,
119 AVCodecContext
*avctx
,
120 const uint8_t **poutbuf
, int *poutbuf_size
,
121 const uint8_t *buf
, int buf_size
)
123 DNXHDParserContext
*dctx
= s
->priv_data
;
124 ParseContext
*pc
= &dctx
->pc
;
127 if (s
->flags
& PARSER_FLAG_COMPLETE_FRAMES
) {
130 next
= dnxhd_find_frame_end(dctx
, buf
, buf_size
);
131 if (ff_combine_frame(pc
, next
, &buf
, &buf_size
) < 0) {
138 *poutbuf_size
= buf_size
;
142 const FFCodecParser ff_dnxhd_parser
= {
143 PARSER_CODEC_LIST(AV_CODEC_ID_DNXHD
),
144 .priv_data_size
= sizeof(DNXHDParserContext
),
145 .parse
= dnxhd_parse
,
146 .close
= ff_parse_close
,