FFmpeg
Loading...
Searching...
No Matches
h261_parser.c
Go to the documentation of this file.
1/*
2 * H.261 parser
3 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4 * Copyright (c) 2004 Maarten Daniels
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23/**
24 * @file
25 * H.261 parser
26 */
27
28#include "parser.h"
29#include "parser_internal.h"
30
32 const uint8_t *buf, int buf_size)
33{
34 int vop_found, i, j;
35 uint32_t state;
36
37 vop_found = pc->frame_start_found;
38 state = pc->state;
39
40 for (i = 0; i < buf_size && !vop_found; i++) {
41 state = (state << 8) | buf[i];
42 for (j = 0; j < 8; j++) {
43 if (((state >> j) & 0xFFFFF0) == 0x000100) {
44 vop_found = 1;
45 break;
46 }
47 }
48 }
49 if (vop_found) {
50 for (; i < buf_size; i++) {
51 state = (state << 8) | buf[i];
52 for (j = 0; j < 8; j++) {
53 if (((state >> j) & 0xFFFFF0) == 0x000100) {
54 pc->frame_start_found = 0;
55 pc->state = (state >> (3 * 8)) + 0xFF00;
56 return i - 2;
57 }
58 }
59 }
60 }
61
62 pc->frame_start_found = vop_found;
63 pc->state = state;
64 return END_NOT_FOUND;
65}
66
68 AVCodecContext *avctx,
69 const uint8_t **poutbuf, int *poutbuf_size,
70 const uint8_t *buf, int buf_size)
71{
72 ParseContext *pc = s->priv_data;
73 int next;
74
75 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) {
76 next = buf_size;
77 } else {
78 next = h261_find_frame_end(pc, avctx, buf, buf_size);
79 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
80 *poutbuf = NULL;
81 *poutbuf_size = 0;
82 return buf_size;
83 }
84 }
85 *poutbuf = buf;
86 *poutbuf_size = buf_size;
87 return next;
88}
89
92 .priv_data_size = sizeof(ParseContext),
95};
static int parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition apv_parser.c:92
static av_cold void close(AVCodecParserContext *s)
Definition apv_parser.c:197
#define PARSER_FLAG_COMPLETE_FRAMES
Definition avcodec.h:2651
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define NULL
Definition coverity.c:32
static struct @346255127015250356166251341105367306144006377143 state
@ AV_CODEC_ID_H261
Definition codec_id.h:53
const FFCodecParser ff_h261_parser
Definition h261_parser.c:90
static int h261_find_frame_end(ParseContext *pc, AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition h261_parser.c:31
static int h261_parse(AVCodecParserContext *s, AVCodecContext *avctx, const uint8_t **poutbuf, int *poutbuf_size, const uint8_t *buf, int buf_size)
Definition h261_parser.c:67
av_cold void ff_parse_close(AVCodecParserContext *s)
Definition parser.c:300
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:213
#define END_NOT_FOUND
Definition parser.h:40
#define PARSER_CODEC_LIST(...)
main external API structure.
Definition avcodec.h:443
uint32_t state
contains the last few bytes in MSB order
Definition parser.h:33
int frame_start_found
Definition parser.h:34