FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dnxhd_parser.c
Go to the documentation of this file.
1 /*
2  * DNxHD/VC-3 parser
3  * Copyright (c) 2008 Baptiste Coudurier <baptiste.coudurier@free.fr>
4  *
5  * This file is part of FFmpeg.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 /**
23  * @file
24  * DNxHD/VC-3 parser
25  */
26 
27 #include "parser.h"
28 #include "dnxhddata.h"
29 
30 typedef struct {
33  int cur_field; /* first field is 0, second is 1 */
35 
37  const uint8_t *buf, int buf_size)
38 {
39  ParseContext *pc = &dctx->pc;
40  uint64_t state = pc->state64;
41  int pic_found = pc->frame_start_found;
42  int i = 0;
43  int interlaced = dctx->interlaced;
44  int cur_field = dctx->cur_field;
45 
46  if (!pic_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) {
50  i++;
51  pic_found = 1;
52  interlaced = (state&2)>>1; /* byte following the 5-byte header prefix */
53  cur_field = state&1;
54  break;
55  }
56  }
57  }
58 
59  if (pic_found) {
60  if (!buf_size) /* EOF considered as end of frame */
61  return 0;
62  for (; i < buf_size; i++) {
63  state = (state << 8) | buf[i];
64  if (ff_dnxhd_check_header_prefix(state & 0xffffffffff00LL) != 0) {
65  if (!interlaced || dctx->cur_field) {
66  pc->frame_start_found = 0;
67  pc->state64 = -1;
68  dctx->interlaced = interlaced;
69  dctx->cur_field = 0;
70  return i - 5;
71  } else {
72  /* continue, to get the second field */
73  dctx->interlaced = interlaced = (state&2)>>1;
74  dctx->cur_field = cur_field = state&1;
75  }
76  }
77  }
78  }
79  pc->frame_start_found = pic_found;
80  pc->state64 = state;
81  dctx->interlaced = interlaced;
82  dctx->cur_field = cur_field;
83  return END_NOT_FOUND;
84 }
85 
87  AVCodecContext *avctx,
88  const uint8_t **poutbuf, int *poutbuf_size,
89  const uint8_t *buf, int buf_size)
90 {
91  DNXHDParserContext *dctx = s->priv_data;
92  ParseContext *pc = &dctx->pc;
93  int next;
94 
96  next = buf_size;
97  } else {
98  next = dnxhd_find_frame_end(dctx, buf, buf_size);
99  if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
100  *poutbuf = NULL;
101  *poutbuf_size = 0;
102  return buf_size;
103  }
104  }
105  *poutbuf = buf;
106  *poutbuf_size = buf_size;
107  return next;
108 }
109 
112  .priv_data_size = sizeof(DNXHDParserContext),
113  .parser_parse = dnxhd_parse,
114  .parser_close = ff_parse_close,
115 };
#define NULL
Definition: coverity.c:32
static av_always_inline uint64_t ff_dnxhd_check_header_prefix(uint64_t prefix)
Definition: dnxhddata.h:68
const char * s
Definition: avisynth_c.h:631
int codec_ids[5]
Definition: avcodec.h:4589
int frame_start_found
Definition: parser.h:34
uint8_t
static int dnxhd_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition: dnxhd_parser.c:86
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
Definition: parser.c:243
AVCodecParser ff_dnxhd_parser
Definition: dnxhd_parser.c:110
void ff_parse_close(AVCodecParserContext *s)
Definition: parser.c:319
static int dnxhd_find_frame_end(DNXHDParserContext *dctx, const uint8_t *buf, int buf_size)
Definition: dnxhd_parser.c:36
uint8_t interlaced
Definition: mxfenc.c:1823
ParseContext pc
Definition: dnxhd_parser.c:31
main external API structure.
Definition: avcodec.h:1532
void * buf
Definition: avisynth_c.h:553
uint64_t state64
contains the last 8 bytes in MSB order
Definition: parser.h:37
#define END_NOT_FOUND
Definition: parser.h:40
#define PARSER_FLAG_COMPLETE_FRAMES
Definition: avcodec.h:4455
static struct @205 state