Coverage Report

Created: 2026-09-01 07:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/packetizer_helper.h
Line
Count
Source
1
/*****************************************************************************
2
 * packetizer_helper.h: Packetizer helpers
3
 *****************************************************************************
4
 * Copyright (C) 2009 Laurent Aimar
5
 *
6
 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program 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
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
#ifndef VLC_PACKETIZER_HELPER_H_
24
#define VLC_PACKETIZER_HELPER_H_
25
26
#include <vlc_block.h>
27
28
enum vlc_packetizer_state
29
{
30
    STATE_NOSYNC,
31
    STATE_SYNC,
32
    STATE_HEADER,
33
    STATE_NEXT_SYNC,
34
    STATE_GET_DATA,
35
    STATE_SEND_DATA,
36
    STATE_CUSTOM_FIRST,
37
};
38
39
typedef void (*packetizer_reset_t)( void *p_private, bool b_flush );
40
typedef block_t *(*packetizer_parse_t)( void *p_private, bool *pb_ts_used, block_t * );
41
typedef block_t *(*packetizer_drain_t)( void *p_private );
42
typedef int (*packetizer_validate_t)( void *p_private, block_t * );
43
44
typedef struct
45
{
46
    block_bytestream_t bytestream;
47
    bool b_synched;
48
49
    size_t startcode_len;
50
    const uint8_t *p_startcode;
51
    block_startcode_helper_t pf_startcode_helper;
52
53
    int i_au_prepend;
54
    const uint8_t *p_au_prepend;
55
56
    unsigned i_au_min_size;
57
58
    void *p_private;
59
    packetizer_reset_t    pf_reset;
60
    packetizer_parse_t    pf_parse;
61
    packetizer_validate_t pf_validate;
62
    packetizer_drain_t    pf_drain;
63
64
} packetizer_t;
65
66
static inline void packetizer_Init( packetizer_t *p_pack,
67
                                    const uint8_t *p_startcode, size_t i_startcode,
68
                                    block_startcode_helper_t pf_start_helper,
69
                                    const uint8_t *p_au_prepend, int i_au_prepend,
70
                                    unsigned i_au_min_size,
71
                                    packetizer_reset_t pf_reset,
72
                                    packetizer_parse_t pf_parse,
73
                                    packetizer_validate_t pf_validate,
74
                                    packetizer_drain_t pf_drain,
75
                                    void *p_private )
76
148k
{
77
148k
    p_pack->b_synched = false;
78
148k
    block_BytestreamInit( &p_pack->bytestream );
79
80
148k
    p_pack->i_au_prepend = i_au_prepend;
81
148k
    p_pack->p_au_prepend = p_au_prepend;
82
148k
    p_pack->i_au_min_size = i_au_min_size;
83
84
148k
    p_pack->startcode_len = i_startcode;
85
148k
    p_pack->p_startcode = p_startcode;
86
148k
    p_pack->pf_startcode_helper = pf_start_helper;
87
148k
    p_pack->pf_reset = pf_reset;
88
148k
    p_pack->pf_parse = pf_parse;
89
148k
    p_pack->pf_validate = pf_validate;
90
148k
    p_pack->pf_drain = pf_drain;
91
148k
    p_pack->p_private = p_private;
92
148k
}
Unexecuted instantiation: a52.c:packetizer_Init
Unexecuted instantiation: dts.c:packetizer_Init
Unexecuted instantiation: flac.c:packetizer_Init
h264.c:packetizer_Init
Line
Count
Source
76
64.8k
{
77
64.8k
    p_pack->b_synched = false;
78
64.8k
    block_BytestreamInit( &p_pack->bytestream );
79
80
64.8k
    p_pack->i_au_prepend = i_au_prepend;
81
64.8k
    p_pack->p_au_prepend = p_au_prepend;
82
64.8k
    p_pack->i_au_min_size = i_au_min_size;
83
84
64.8k
    p_pack->startcode_len = i_startcode;
85
64.8k
    p_pack->p_startcode = p_startcode;
86
64.8k
    p_pack->pf_startcode_helper = pf_start_helper;
87
64.8k
    p_pack->pf_reset = pf_reset;
88
64.8k
    p_pack->pf_parse = pf_parse;
89
64.8k
    p_pack->pf_validate = pf_validate;
90
64.8k
    p_pack->pf_drain = pf_drain;
91
64.8k
    p_pack->p_private = p_private;
92
64.8k
}
hevc.c:packetizer_Init
Line
Count
Source
76
11.2k
{
77
11.2k
    p_pack->b_synched = false;
78
11.2k
    block_BytestreamInit( &p_pack->bytestream );
79
80
11.2k
    p_pack->i_au_prepend = i_au_prepend;
81
11.2k
    p_pack->p_au_prepend = p_au_prepend;
82
11.2k
    p_pack->i_au_min_size = i_au_min_size;
83
84
11.2k
    p_pack->startcode_len = i_startcode;
85
11.2k
    p_pack->p_startcode = p_startcode;
86
11.2k
    p_pack->pf_startcode_helper = pf_start_helper;
87
11.2k
    p_pack->pf_reset = pf_reset;
88
11.2k
    p_pack->pf_parse = pf_parse;
89
11.2k
    p_pack->pf_validate = pf_validate;
90
11.2k
    p_pack->pf_drain = pf_drain;
91
11.2k
    p_pack->p_private = p_private;
92
11.2k
}
Unexecuted instantiation: mlp.c:packetizer_Init
Unexecuted instantiation: mpeg4audio.c:packetizer_Init
mpeg4video.c:packetizer_Init
Line
Count
Source
76
7.19k
{
77
7.19k
    p_pack->b_synched = false;
78
7.19k
    block_BytestreamInit( &p_pack->bytestream );
79
80
7.19k
    p_pack->i_au_prepend = i_au_prepend;
81
7.19k
    p_pack->p_au_prepend = p_au_prepend;
82
7.19k
    p_pack->i_au_min_size = i_au_min_size;
83
84
7.19k
    p_pack->startcode_len = i_startcode;
85
7.19k
    p_pack->p_startcode = p_startcode;
86
7.19k
    p_pack->pf_startcode_helper = pf_start_helper;
87
7.19k
    p_pack->pf_reset = pf_reset;
88
7.19k
    p_pack->pf_parse = pf_parse;
89
7.19k
    p_pack->pf_validate = pf_validate;
90
7.19k
    p_pack->pf_drain = pf_drain;
91
7.19k
    p_pack->p_private = p_private;
92
7.19k
}
Unexecuted instantiation: mpegaudio.c:packetizer_Init
mpegvideo.c:packetizer_Init
Line
Count
Source
76
60.3k
{
77
60.3k
    p_pack->b_synched = false;
78
60.3k
    block_BytestreamInit( &p_pack->bytestream );
79
80
60.3k
    p_pack->i_au_prepend = i_au_prepend;
81
60.3k
    p_pack->p_au_prepend = p_au_prepend;
82
60.3k
    p_pack->i_au_min_size = i_au_min_size;
83
84
60.3k
    p_pack->startcode_len = i_startcode;
85
60.3k
    p_pack->p_startcode = p_startcode;
86
60.3k
    p_pack->pf_startcode_helper = pf_start_helper;
87
60.3k
    p_pack->pf_reset = pf_reset;
88
60.3k
    p_pack->pf_parse = pf_parse;
89
60.3k
    p_pack->pf_validate = pf_validate;
90
60.3k
    p_pack->pf_drain = pf_drain;
91
60.3k
    p_pack->p_private = p_private;
92
60.3k
}
vc1.c:packetizer_Init
Line
Count
Source
76
5.29k
{
77
5.29k
    p_pack->b_synched = false;
78
5.29k
    block_BytestreamInit( &p_pack->bytestream );
79
80
5.29k
    p_pack->i_au_prepend = i_au_prepend;
81
5.29k
    p_pack->p_au_prepend = p_au_prepend;
82
5.29k
    p_pack->i_au_min_size = i_au_min_size;
83
84
5.29k
    p_pack->startcode_len = i_startcode;
85
5.29k
    p_pack->p_startcode = p_startcode;
86
5.29k
    p_pack->pf_startcode_helper = pf_start_helper;
87
5.29k
    p_pack->pf_reset = pf_reset;
88
5.29k
    p_pack->pf_parse = pf_parse;
89
5.29k
    p_pack->pf_validate = pf_validate;
90
5.29k
    p_pack->pf_drain = pf_drain;
91
5.29k
    p_pack->p_private = p_private;
92
5.29k
}
mjpeg.c:packetizer_Init
Line
Count
Source
76
7
{
77
7
    p_pack->b_synched = false;
78
7
    block_BytestreamInit( &p_pack->bytestream );
79
80
7
    p_pack->i_au_prepend = i_au_prepend;
81
7
    p_pack->p_au_prepend = p_au_prepend;
82
7
    p_pack->i_au_min_size = i_au_min_size;
83
84
7
    p_pack->startcode_len = i_startcode;
85
7
    p_pack->p_startcode = p_startcode;
86
7
    p_pack->pf_startcode_helper = pf_start_helper;
87
7
    p_pack->pf_reset = pf_reset;
88
7
    p_pack->pf_parse = pf_parse;
89
7
    p_pack->pf_validate = pf_validate;
90
7
    p_pack->pf_drain = pf_drain;
91
7
    p_pack->p_private = p_private;
92
7
}
93
94
static inline void packetizer_Clean( packetizer_t *p_pack )
95
148k
{
96
148k
    block_BytestreamRelease( &p_pack->bytestream );
97
148k
}
Unexecuted instantiation: a52.c:packetizer_Clean
Unexecuted instantiation: dts.c:packetizer_Clean
Unexecuted instantiation: flac.c:packetizer_Clean
h264.c:packetizer_Clean
Line
Count
Source
95
64.8k
{
96
64.8k
    block_BytestreamRelease( &p_pack->bytestream );
97
64.8k
}
hevc.c:packetizer_Clean
Line
Count
Source
95
11.2k
{
96
11.2k
    block_BytestreamRelease( &p_pack->bytestream );
97
11.2k
}
Unexecuted instantiation: mlp.c:packetizer_Clean
Unexecuted instantiation: mpeg4audio.c:packetizer_Clean
mpeg4video.c:packetizer_Clean
Line
Count
Source
95
7.19k
{
96
7.19k
    block_BytestreamRelease( &p_pack->bytestream );
97
7.19k
}
Unexecuted instantiation: mpegaudio.c:packetizer_Clean
mpegvideo.c:packetizer_Clean
Line
Count
Source
95
60.3k
{
96
60.3k
    block_BytestreamRelease( &p_pack->bytestream );
97
60.3k
}
vc1.c:packetizer_Clean
Line
Count
Source
95
5.29k
{
96
5.29k
    block_BytestreamRelease( &p_pack->bytestream );
97
5.29k
}
mjpeg.c:packetizer_Clean
Line
Count
Source
95
7
{
96
7
    block_BytestreamRelease( &p_pack->bytestream );
97
7
}
98
99
static inline void packetizer_Flush( packetizer_t *p_pack )
100
0
{
101
0
    p_pack->b_synched = false;
102
0
    block_BytestreamEmpty( &p_pack->bytestream );
103
0
    p_pack->pf_reset( p_pack->p_private, true );
104
0
}
Unexecuted instantiation: a52.c:packetizer_Flush
Unexecuted instantiation: dts.c:packetizer_Flush
Unexecuted instantiation: flac.c:packetizer_Flush
Unexecuted instantiation: h264.c:packetizer_Flush
Unexecuted instantiation: hevc.c:packetizer_Flush
Unexecuted instantiation: mlp.c:packetizer_Flush
Unexecuted instantiation: mpeg4audio.c:packetizer_Flush
Unexecuted instantiation: mpeg4video.c:packetizer_Flush
Unexecuted instantiation: mpegaudio.c:packetizer_Flush
Unexecuted instantiation: mpegvideo.c:packetizer_Flush
Unexecuted instantiation: vc1.c:packetizer_Flush
Unexecuted instantiation: mjpeg.c:packetizer_Flush
105
106
/**
107
 * Return a block of the data between 2 startcodes in the block stream.
108
 * The block contains the startcode at the beginning.
109
 */
110
static block_t *packetizer_PacketizeBlock( packetizer_t *p_pack, block_t **pp_block )
111
8.61M
{
112
8.61M
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
8.61M
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
144k
        return NULL;
116
117
8.47M
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
296k
    {
119
296k
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
296k
        if( p_drained )
121
25.1k
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
270k
        p_pack->b_synched = false;
124
270k
        block_BytestreamEmpty( &p_pack->bytestream );
125
270k
        p_pack->pf_reset( p_pack->p_private, false );
126
270k
    }
127
128
8.44M
    if( p_block )
129
7.91M
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
8.44M
    for( ;; )
132
18.5M
    {
133
18.5M
        bool b_used_ts;
134
18.5M
        block_t *p_pic;
135
136
18.5M
        if( !p_pack->b_synched )
137
15.6M
        {
138
15.6M
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
15.6M
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
15.6M
                                                p_pack->p_startcode, p_pack->startcode_len,
142
15.6M
                                                p_pack->pf_startcode_helper, NULL ) )
143
506k
            {
144
506k
                return NULL; /* Need more data */
145
506k
            }
146
147
15.1M
            p_pack->b_synched = true;
148
149
15.1M
            if( block_startcode_offset )
150
178k
            {
151
                // remove junk data before the startcode
152
178k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
178k
                block_BytestreamFlush( &p_pack->bytestream );
154
178k
            }
155
15.1M
        }
156
157
18.0M
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
18.0M
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
18.0M
                                           p_pack->p_startcode, p_pack->startcode_len,
161
18.0M
                                           p_pack->pf_startcode_helper, NULL ) )
162
3.13M
        {
163
3.13M
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
2.88M
            {
165
2.88M
                return NULL; /* Need more data */
166
2.88M
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
249k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
249k
            if( block_size == 0 )
172
197
                return NULL;
173
174
249k
            if( block_size <= p_pack->startcode_len &&
175
4.41k
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
4.40k
            {
177
4.40k
                block_SkipBytes( &p_pack->bytestream, block_size );
178
4.40k
                return NULL;
179
4.40k
            }
180
249k
        }
181
182
15.1M
        block_BytestreamFlush( &p_pack->bytestream );
183
15.1M
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
15.1M
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
64.4k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
64.4k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
64.4k
            return NULL;
191
64.4k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
15.0M
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
15.0M
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
15.0M
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
15.0M
        p_pic->i_pts = p_block_bytestream->i_pts;
205
15.0M
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
15.0M
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
9.74k
             p_block_bytestream->i_buffer == block_size )
210
4
        {
211
4
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
4
        }
213
214
15.0M
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
15.0M
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
15.0M
        if( p_pack->i_au_prepend > 0 )
217
9.95M
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
15.0M
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
15.0M
        if( b_used_ts )
222
7.02M
        {
223
7.02M
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
7.02M
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
7.02M
        }
226
227
15.0M
        if( !p_pic )
228
10.0M
        {
229
10.0M
            continue;
230
10.0M
        }
231
5.01M
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
30.8k
        {
233
30.8k
            block_Release( p_pic );
234
30.8k
            continue;
235
30.8k
        }
236
237
        /* So p_block doesn't get re-added several times */
238
4.98M
        if( pp_block )
239
4.82M
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
4.98M
        return p_pic;
242
5.01M
    }
243
8.44M
}
Unexecuted instantiation: a52.c:packetizer_PacketizeBlock
Unexecuted instantiation: dts.c:packetizer_PacketizeBlock
Unexecuted instantiation: flac.c:packetizer_PacketizeBlock
h264.c:packetizer_PacketizeBlock
Line
Count
Source
111
796k
{
112
796k
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
796k
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
85.7k
        return NULL;
116
117
710k
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
206k
    {
119
206k
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
206k
        if( p_drained )
121
22.3k
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
184k
        p_pack->b_synched = false;
124
184k
        block_BytestreamEmpty( &p_pack->bytestream );
125
184k
        p_pack->pf_reset( p_pack->p_private, false );
126
184k
    }
127
128
688k
    if( p_block )
129
430k
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
688k
    for( ;; )
132
2.14M
    {
133
2.14M
        bool b_used_ts;
134
2.14M
        block_t *p_pic;
135
136
2.14M
        if( !p_pack->b_synched )
137
1.89M
        {
138
1.89M
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
1.89M
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
1.89M
                                                p_pack->p_startcode, p_pack->startcode_len,
142
1.89M
                                                p_pack->pf_startcode_helper, NULL ) )
143
287k
            {
144
287k
                return NULL; /* Need more data */
145
287k
            }
146
147
1.60M
            p_pack->b_synched = true;
148
149
1.60M
            if( block_startcode_offset )
150
92.1k
            {
151
                // remove junk data before the startcode
152
92.1k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
92.1k
                block_BytestreamFlush( &p_pack->bytestream );
154
92.1k
            }
155
1.60M
        }
156
157
1.85M
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
1.85M
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
1.85M
                                           p_pack->p_startcode, p_pack->startcode_len,
161
1.85M
                                           p_pack->pf_startcode_helper, NULL ) )
162
400k
        {
163
400k
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
250k
            {
165
250k
                return NULL; /* Need more data */
166
250k
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
149k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
149k
            if( block_size == 0 )
172
14
                return NULL;
173
174
149k
            if( block_size <= p_pack->startcode_len &&
175
1.49k
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
1.49k
            {
177
1.49k
                block_SkipBytes( &p_pack->bytestream, block_size );
178
1.49k
                return NULL;
179
1.49k
            }
180
149k
        }
181
182
1.60M
        block_BytestreamFlush( &p_pack->bytestream );
183
1.60M
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
1.60M
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
5.21k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
5.21k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
5.21k
            return NULL;
191
5.21k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
1.59M
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
1.59M
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
1.59M
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
1.59M
        p_pic->i_pts = p_block_bytestream->i_pts;
205
1.59M
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
1.59M
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
0
             p_block_bytestream->i_buffer == block_size )
210
0
        {
211
0
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
0
        }
213
214
1.59M
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
1.59M
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
1.59M
        if( p_pack->i_au_prepend > 0 )
217
1.59M
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
1.59M
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
1.59M
        if( b_used_ts )
222
1.14M
        {
223
1.14M
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
1.14M
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
1.14M
        }
226
227
1.59M
        if( !p_pic )
228
1.45M
        {
229
1.45M
            continue;
230
1.45M
        }
231
143k
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
0
        {
233
0
            block_Release( p_pic );
234
0
            continue;
235
0
        }
236
237
        /* So p_block doesn't get re-added several times */
238
143k
        if( pp_block )
239
93.5k
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
143k
        return p_pic;
242
143k
    }
243
688k
}
hevc.c:packetizer_PacketizeBlock
Line
Count
Source
111
5.77M
{
112
5.77M
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
5.77M
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
5.45k
        return NULL;
116
117
5.77M
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
5.76k
    {
119
5.76k
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
5.76k
        if( p_drained )
121
114
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
5.65k
        p_pack->b_synched = false;
124
5.65k
        block_BytestreamEmpty( &p_pack->bytestream );
125
5.65k
        p_pack->pf_reset( p_pack->p_private, false );
126
5.65k
    }
127
128
5.77M
    if( p_block )
129
5.71M
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
5.77M
    for( ;; )
132
10.3M
    {
133
10.3M
        bool b_used_ts;
134
10.3M
        block_t *p_pic;
135
136
10.3M
        if( !p_pack->b_synched )
137
8.41M
        {
138
8.41M
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
8.41M
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
8.41M
                                                p_pack->p_startcode, p_pack->startcode_len,
142
8.41M
                                                p_pack->pf_startcode_helper, NULL ) )
143
23.4k
            {
144
23.4k
                return NULL; /* Need more data */
145
23.4k
            }
146
147
8.39M
            p_pack->b_synched = true;
148
149
8.39M
            if( block_startcode_offset )
150
12.1k
            {
151
                // remove junk data before the startcode
152
12.1k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
12.1k
                block_BytestreamFlush( &p_pack->bytestream );
154
12.1k
            }
155
8.39M
        }
156
157
10.3M
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
10.3M
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
10.3M
                                           p_pack->p_startcode, p_pack->startcode_len,
161
10.3M
                                           p_pack->pf_startcode_helper, NULL ) )
162
1.98M
        {
163
1.98M
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
1.97M
            {
165
1.97M
                return NULL; /* Need more data */
166
1.97M
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
11.0k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
11.0k
            if( block_size == 0 )
172
24
                return NULL;
173
174
11.0k
            if( block_size <= p_pack->startcode_len &&
175
487
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
487
            {
177
487
                block_SkipBytes( &p_pack->bytestream, block_size );
178
487
                return NULL;
179
487
            }
180
11.0k
        }
181
182
8.39M
        block_BytestreamFlush( &p_pack->bytestream );
183
8.39M
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
8.39M
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
30.5k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
30.5k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
30.5k
            return NULL;
191
30.5k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
8.36M
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
8.36M
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
8.36M
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
8.36M
        p_pic->i_pts = p_block_bytestream->i_pts;
205
8.36M
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
8.36M
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
6.26k
             p_block_bytestream->i_buffer == block_size )
210
1
        {
211
1
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
1
        }
213
214
8.36M
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
8.36M
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
8.36M
        if( p_pack->i_au_prepend > 0 )
217
8.36M
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
8.36M
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
8.36M
        if( b_used_ts )
222
4.42M
        {
223
4.42M
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
4.42M
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
4.42M
        }
226
227
8.36M
        if( !p_pic )
228
4.61M
        {
229
4.61M
            continue;
230
4.61M
        }
231
3.74M
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
0
        {
233
0
            block_Release( p_pic );
234
0
            continue;
235
0
        }
236
237
        /* So p_block doesn't get re-added several times */
238
3.74M
        if( pp_block )
239
3.73M
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
3.74M
        return p_pic;
242
3.74M
    }
243
5.77M
}
Unexecuted instantiation: mlp.c:packetizer_PacketizeBlock
Unexecuted instantiation: mpeg4audio.c:packetizer_PacketizeBlock
mpeg4video.c:packetizer_PacketizeBlock
Line
Count
Source
111
128k
{
112
128k
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
128k
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
5.94k
        return NULL;
116
117
122k
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
32.5k
    {
119
32.5k
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
32.5k
        if( p_drained )
121
1.09k
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
31.4k
        p_pack->b_synched = false;
124
31.4k
        block_BytestreamEmpty( &p_pack->bytestream );
125
31.4k
        p_pack->pf_reset( p_pack->p_private, false );
126
31.4k
    }
127
128
121k
    if( p_block )
129
87.0k
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
121k
    for( ;; )
132
506k
    {
133
506k
        bool b_used_ts;
134
506k
        block_t *p_pic;
135
136
506k
        if( !p_pack->b_synched )
137
435k
        {
138
435k
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
435k
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
435k
                                                p_pack->p_startcode, p_pack->startcode_len,
142
435k
                                                p_pack->pf_startcode_helper, NULL ) )
143
43.4k
            {
144
43.4k
                return NULL; /* Need more data */
145
43.4k
            }
146
147
391k
            p_pack->b_synched = true;
148
149
391k
            if( block_startcode_offset )
150
29.2k
            {
151
                // remove junk data before the startcode
152
29.2k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
29.2k
                block_BytestreamFlush( &p_pack->bytestream );
154
29.2k
            }
155
391k
        }
156
157
462k
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
462k
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
462k
                                           p_pack->p_startcode, p_pack->startcode_len,
161
462k
                                           p_pack->pf_startcode_helper, NULL ) )
162
100k
        {
163
100k
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
70.9k
            {
165
70.9k
                return NULL; /* Need more data */
166
70.9k
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
29.2k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
29.2k
            if( block_size == 0 )
172
0
                return NULL;
173
174
29.2k
            if( block_size <= p_pack->startcode_len &&
175
872
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
872
            {
177
872
                block_SkipBytes( &p_pack->bytestream, block_size );
178
872
                return NULL;
179
872
            }
180
29.2k
        }
181
182
391k
        block_BytestreamFlush( &p_pack->bytestream );
183
391k
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
391k
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
1.80k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
1.80k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
1.80k
            return NULL;
191
1.80k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
389k
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
389k
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
389k
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
389k
        p_pic->i_pts = p_block_bytestream->i_pts;
205
389k
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
389k
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
697
             p_block_bytestream->i_buffer == block_size )
210
0
        {
211
0
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
0
        }
213
214
389k
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
389k
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
389k
        if( p_pack->i_au_prepend > 0 )
217
0
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
389k
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
389k
        if( b_used_ts )
222
43
        {
223
43
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
43
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
43
        }
226
227
389k
        if( !p_pic )
228
384k
        {
229
384k
            continue;
230
384k
        }
231
4.63k
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
0
        {
233
0
            block_Release( p_pic );
234
0
            continue;
235
0
        }
236
237
        /* So p_block doesn't get re-added several times */
238
4.63k
        if( pp_block )
239
2.67k
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
4.63k
        return p_pic;
242
4.63k
    }
243
121k
}
Unexecuted instantiation: mpegaudio.c:packetizer_PacketizeBlock
mpegvideo.c:packetizer_PacketizeBlock
Line
Count
Source
111
929k
{
112
929k
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
929k
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
47.7k
        return NULL;
116
117
882k
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
50.4k
    {
119
50.4k
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
50.4k
        if( p_drained )
121
1.56k
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
48.8k
        p_pack->b_synched = false;
124
48.8k
        block_BytestreamEmpty( &p_pack->bytestream );
125
48.8k
        p_pack->pf_reset( p_pack->p_private, false );
126
48.8k
    }
127
128
880k
    if( p_block )
129
740k
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
880k
    for( ;; )
132
3.39M
    {
133
3.39M
        bool b_used_ts;
134
3.39M
        block_t *p_pic;
135
136
3.39M
        if( !p_pack->b_synched )
137
3.01M
        {
138
3.01M
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
3.01M
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
3.01M
                                                p_pack->p_startcode, p_pack->startcode_len,
142
3.01M
                                                p_pack->pf_startcode_helper, NULL ) )
143
137k
            {
144
137k
                return NULL; /* Need more data */
145
137k
            }
146
147
2.88M
            p_pack->b_synched = true;
148
149
2.88M
            if( block_startcode_offset )
150
43.3k
            {
151
                // remove junk data before the startcode
152
43.3k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
43.3k
                block_BytestreamFlush( &p_pack->bytestream );
154
43.3k
            }
155
2.88M
        }
156
157
3.25M
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
3.25M
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
3.25M
                                           p_pack->p_startcode, p_pack->startcode_len,
161
3.25M
                                           p_pack->pf_startcode_helper, NULL ) )
162
425k
        {
163
425k
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
373k
            {
165
373k
                return NULL; /* Need more data */
166
373k
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
52.0k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
52.0k
            if( block_size == 0 )
172
105
                return NULL;
173
174
51.9k
            if( block_size <= p_pack->startcode_len &&
175
1.45k
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
1.44k
            {
177
1.44k
                block_SkipBytes( &p_pack->bytestream, block_size );
178
1.44k
                return NULL;
179
1.44k
            }
180
51.9k
        }
181
182
2.88M
        block_BytestreamFlush( &p_pack->bytestream );
183
2.88M
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
2.88M
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
19.4k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
19.4k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
19.4k
            return NULL;
191
19.4k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
2.86M
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
2.86M
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
2.86M
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
2.86M
        p_pic->i_pts = p_block_bytestream->i_pts;
205
2.86M
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
2.86M
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
2.78k
             p_block_bytestream->i_buffer == block_size )
210
3
        {
211
3
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
3
        }
213
214
2.86M
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
2.86M
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
2.86M
        if( p_pack->i_au_prepend > 0 )
217
0
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
2.86M
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
2.86M
        if( b_used_ts )
222
85.7k
        {
223
85.7k
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
85.7k
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
85.7k
        }
226
227
2.86M
        if( !p_pic )
228
2.48M
        {
229
2.48M
            continue;
230
2.48M
        }
231
373k
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
25.7k
        {
233
25.7k
            block_Release( p_pic );
234
25.7k
            continue;
235
25.7k
        }
236
237
        /* So p_block doesn't get re-added several times */
238
348k
        if( pp_block )
239
282k
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
348k
        return p_pic;
242
373k
    }
243
880k
}
vc1.c:packetizer_PacketizeBlock
Line
Count
Source
111
979k
{
112
979k
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
979k
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
104
        return NULL;
116
117
979k
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
767
    {
119
767
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
767
        if( p_drained )
121
36
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
731
        p_pack->b_synched = false;
124
731
        block_BytestreamEmpty( &p_pack->bytestream );
125
731
        p_pack->pf_reset( p_pack->p_private, false );
126
731
    }
127
128
979k
    if( p_block )
129
937k
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
979k
    for( ;; )
132
2.10M
    {
133
2.10M
        bool b_used_ts;
134
2.10M
        block_t *p_pic;
135
136
2.10M
        if( !p_pack->b_synched )
137
1.88M
        {
138
1.88M
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
1.88M
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
1.88M
                                                p_pack->p_startcode, p_pack->startcode_len,
142
1.88M
                                                p_pack->pf_startcode_helper, NULL ) )
143
13.5k
            {
144
13.5k
                return NULL; /* Need more data */
145
13.5k
            }
146
147
1.87M
            p_pack->b_synched = true;
148
149
1.87M
            if( block_startcode_offset )
150
1.87k
            {
151
                // remove junk data before the startcode
152
1.87k
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
1.87k
                block_BytestreamFlush( &p_pack->bytestream );
154
1.87k
            }
155
1.87M
        }
156
157
2.08M
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
2.08M
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
2.08M
                                           p_pack->p_startcode, p_pack->startcode_len,
161
2.08M
                                           p_pack->pf_startcode_helper, NULL ) )
162
221k
        {
163
221k
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
214k
            {
165
214k
                return NULL; /* Need more data */
166
214k
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
7.19k
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
7.19k
            if( block_size == 0 )
172
54
                return NULL;
173
174
7.14k
            if( block_size <= p_pack->startcode_len &&
175
104
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
104
            {
177
104
                block_SkipBytes( &p_pack->bytestream, block_size );
178
104
                return NULL;
179
104
            }
180
7.14k
        }
181
182
1.87M
        block_BytestreamFlush( &p_pack->bytestream );
183
1.87M
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
1.87M
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
7.33k
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
7.33k
            block_SkipBytes( &p_pack->bytestream, block_size );
190
7.33k
            return NULL;
191
7.33k
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
1.86M
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
1.86M
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
1.86M
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
1.86M
        p_pic->i_pts = p_block_bytestream->i_pts;
205
1.86M
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
1.86M
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
0
             p_block_bytestream->i_buffer == block_size )
210
0
        {
211
0
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
0
        }
213
214
1.86M
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
1.86M
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
1.86M
        if( p_pack->i_au_prepend > 0 )
217
0
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
1.86M
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
1.86M
        if( b_used_ts )
222
1.37M
        {
223
1.37M
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
1.37M
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
1.37M
        }
226
227
1.86M
        if( !p_pic )
228
1.11M
        {
229
1.11M
            continue;
230
1.11M
        }
231
749k
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
5.16k
        {
233
5.16k
            block_Release( p_pic );
234
5.16k
            continue;
235
5.16k
        }
236
237
        /* So p_block doesn't get re-added several times */
238
744k
        if( pp_block )
239
716k
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
744k
        return p_pic;
242
749k
    }
243
979k
}
mjpeg.c:packetizer_PacketizeBlock
Line
Count
Source
111
2.23k
{
112
2.23k
    block_t *p_block = ( pp_block ) ? *pp_block : NULL;
113
114
2.23k
    if( p_block == NULL && p_pack->bytestream.p_block == NULL )
115
0
        return NULL;
116
117
2.23k
    if( p_block && unlikely( p_block->i_flags&(BLOCK_FLAG_DISCONTINUITY|BLOCK_FLAG_CORRUPTED) ) )
118
0
    {
119
0
        block_t *p_drained = packetizer_PacketizeBlock( p_pack, NULL );
120
0
        if( p_drained )
121
0
            return p_drained; // FIXME do we lose p_block ? Can we output more than one drain output ?
122
123
0
        p_pack->b_synched = false;
124
0
        block_BytestreamEmpty( &p_pack->bytestream );
125
0
        p_pack->pf_reset( p_pack->p_private, false );
126
0
    }
127
128
2.23k
    if( p_block )
129
2.22k
        block_BytestreamPush( &p_pack->bytestream, p_block );
130
131
2.23k
    for( ;; )
132
2.23k
    {
133
2.23k
        bool b_used_ts;
134
2.23k
        block_t *p_pic;
135
136
2.23k
        if( !p_pack->b_synched )
137
336
        {
138
336
            size_t block_startcode_offset = 0;
139
            /* Find a startcode */
140
336
            if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_startcode_offset,
141
336
                                                p_pack->p_startcode, p_pack->startcode_len,
142
336
                                                p_pack->pf_startcode_helper, NULL ) )
143
198
            {
144
198
                return NULL; /* Need more data */
145
198
            }
146
147
138
            p_pack->b_synched = true;
148
149
138
            if( block_startcode_offset )
150
4
            {
151
                // remove junk data before the startcode
152
4
                block_SkipBytes( &p_pack->bytestream, block_startcode_offset );
153
4
                block_BytestreamFlush( &p_pack->bytestream );
154
4
            }
155
138
        }
156
157
2.03k
        size_t block_size = p_pack->startcode_len;
158
        /* Find the next startcode */
159
2.03k
        if( block_FindStartcodeFromOffset( &p_pack->bytestream, &block_size,
160
2.03k
                                           p_pack->p_startcode, p_pack->startcode_len,
161
2.03k
                                           p_pack->pf_startcode_helper, NULL ) )
162
1.90k
        {
163
1.90k
            if( pp_block /* not draining */ || !p_pack->bytestream.p_chain )
164
1.89k
            {
165
1.89k
                return NULL; /* Need more data */
166
1.89k
            }
167
168
            /* When draining and we don't find a second startcode, suppose that
169
             * the data extend up to the end of the bytestream */
170
5
            block_size = block_BytestreamRemaining(&p_pack->bytestream);
171
5
            if( block_size == 0 )
172
0
                return NULL;
173
174
5
            if( block_size <= p_pack->startcode_len &&
175
0
                (p_pack->bytestream.p_block->i_flags & BLOCK_FLAG_AU_END) == 0 )
176
0
            {
177
0
                block_SkipBytes( &p_pack->bytestream, block_size );
178
0
                return NULL;
179
0
            }
180
5
        }
181
182
138
        block_BytestreamFlush( &p_pack->bytestream );
183
138
        p_pack->b_synched = false; // look for 2 startcodes on next call/loop
184
185
138
        if ( block_size + p_pack->i_au_prepend < p_pack->i_au_min_size )
186
14
        {
187
            // we found 2 startcodes but the amount of data between them is too
188
            // small, discard data until the second startcode
189
14
            block_SkipBytes( &p_pack->bytestream, block_size );
190
14
            return NULL;
191
14
        }
192
193
        /* Get the new fragment and set the pts/dts */
194
124
        block_t *p_block_bytestream = p_pack->bytestream.p_block;
195
196
124
        p_pic = block_Alloc( block_size + p_pack->i_au_prepend );
197
124
        if( p_pic == NULL )
198
0
        {
199
            // we can't output this block, maybe it's too big, we should not try
200
            // to read it will we are fed more data
201
0
            block_SkipBytes( &p_pack->bytestream, block_size );
202
0
            return NULL;
203
0
        }
204
124
        p_pic->i_pts = p_block_bytestream->i_pts;
205
124
        p_pic->i_dts = p_block_bytestream->i_dts;
206
207
        /* Do not wait for next sync code if notified block ends AU */
208
124
        if( (p_block_bytestream->i_flags & BLOCK_FLAG_AU_END) &&
209
0
             p_block_bytestream->i_buffer == block_size )
210
0
        {
211
0
            p_pic->i_flags |= BLOCK_FLAG_AU_END;
212
0
        }
213
214
124
        block_GetBytes( &p_pack->bytestream, &p_pic->p_buffer[p_pack->i_au_prepend],
215
124
                        p_pic->i_buffer - p_pack->i_au_prepend );
216
124
        if( p_pack->i_au_prepend > 0 )
217
0
            memcpy( p_pic->p_buffer, p_pack->p_au_prepend, p_pack->i_au_prepend );
218
219
        /* Parse the NAL */
220
124
        p_pic = p_pack->pf_parse( p_pack->p_private, &b_used_ts, p_pic );
221
124
        if( b_used_ts )
222
124
        {
223
124
            p_block_bytestream->i_dts = VLC_TICK_INVALID;
224
124
            p_block_bytestream->i_pts = VLC_TICK_INVALID;
225
124
        }
226
227
124
        if( !p_pic )
228
0
        {
229
0
            continue;
230
0
        }
231
124
        if( p_pack->pf_validate( p_pack->p_private, p_pic ) )
232
0
        {
233
0
            block_Release( p_pic );
234
0
            continue;
235
0
        }
236
237
        /* So p_block doesn't get re-added several times */
238
124
        if( pp_block )
239
119
            *pp_block = block_BytestreamPop( &p_pack->bytestream );
240
241
124
        return p_pic;
242
124
    }
243
2.23k
}
244
245
static block_t *packetizer_Packetize( packetizer_t *p_pack, block_t **pp_block )
246
8.31M
{
247
8.31M
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
8.31M
    if( p_out )
249
4.98M
        return p_out;
250
    /* handle caller drain */
251
3.33M
    if( pp_block == NULL && p_pack->pf_drain )
252
232k
    {
253
232k
        p_out = p_pack->pf_drain( p_pack->p_private );
254
232k
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
4.13k
        {
256
4.13k
            block_Release( p_out );
257
4.13k
            p_out = NULL;
258
4.13k
        }
259
232k
    }
260
3.33M
    return p_out;
261
8.31M
}
Unexecuted instantiation: a52.c:packetizer_Packetize
Unexecuted instantiation: dts.c:packetizer_Packetize
Unexecuted instantiation: flac.c:packetizer_Packetize
h264.c:packetizer_Packetize
Line
Count
Source
246
589k
{
247
589k
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
589k
    if( p_out )
249
143k
        return p_out;
250
    /* handle caller drain */
251
446k
    if( pp_block == NULL && p_pack->pf_drain )
252
109k
    {
253
109k
        p_out = p_pack->pf_drain( p_pack->p_private );
254
109k
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
0
        {
256
0
            block_Release( p_out );
257
            p_out = NULL;
258
0
        }
259
109k
    }
260
446k
    return p_out;
261
589k
}
hevc.c:packetizer_Packetize
Line
Count
Source
246
5.77M
{
247
5.77M
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
5.77M
    if( p_out )
249
3.74M
        return p_out;
250
    /* handle caller drain */
251
2.02M
    if( pp_block == NULL && p_pack->pf_drain )
252
36.6k
    {
253
36.6k
        p_out = p_pack->pf_drain( p_pack->p_private );
254
36.6k
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
0
        {
256
0
            block_Release( p_out );
257
            p_out = NULL;
258
0
        }
259
36.6k
    }
260
2.02M
    return p_out;
261
5.77M
}
Unexecuted instantiation: mlp.c:packetizer_Packetize
Unexecuted instantiation: mpeg4audio.c:packetizer_Packetize
mpeg4video.c:packetizer_Packetize
Line
Count
Source
246
96.1k
{
247
96.1k
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
96.1k
    if( p_out )
249
4.63k
        return p_out;
250
    /* handle caller drain */
251
91.5k
    if( pp_block == NULL && p_pack->pf_drain )
252
0
    {
253
0
        p_out = p_pack->pf_drain( p_pack->p_private );
254
0
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
0
        {
256
0
            block_Release( p_out );
257
            p_out = NULL;
258
0
        }
259
0
    }
260
91.5k
    return p_out;
261
96.1k
}
Unexecuted instantiation: mpegaudio.c:packetizer_Packetize
mpegvideo.c:packetizer_Packetize
Line
Count
Source
246
879k
{
247
879k
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
879k
    if( p_out )
249
348k
        return p_out;
250
    /* handle caller drain */
251
531k
    if( pp_block == NULL && p_pack->pf_drain )
252
72.8k
    {
253
72.8k
        p_out = p_pack->pf_drain( p_pack->p_private );
254
72.8k
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
4.12k
        {
256
4.12k
            block_Release( p_out );
257
            p_out = NULL;
258
4.12k
        }
259
72.8k
    }
260
531k
    return p_out;
261
879k
}
vc1.c:packetizer_Packetize
Line
Count
Source
246
978k
{
247
978k
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
978k
    if( p_out )
249
744k
        return p_out;
250
    /* handle caller drain */
251
234k
    if( pp_block == NULL && p_pack->pf_drain )
252
13.3k
    {
253
13.3k
        p_out = p_pack->pf_drain( p_pack->p_private );
254
13.3k
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
9
        {
256
9
            block_Release( p_out );
257
            p_out = NULL;
258
9
        }
259
13.3k
    }
260
234k
    return p_out;
261
978k
}
mjpeg.c:packetizer_Packetize
Line
Count
Source
246
2.23k
{
247
2.23k
    block_t *p_out = packetizer_PacketizeBlock( p_pack, pp_block );
248
2.23k
    if( p_out )
249
124
        return p_out;
250
    /* handle caller drain */
251
2.11k
    if( pp_block == NULL && p_pack->pf_drain )
252
0
    {
253
0
        p_out = p_pack->pf_drain( p_pack->p_private );
254
0
        if( p_out && p_pack->pf_validate( p_pack->p_private, p_out ) )
255
0
        {
256
0
            block_Release( p_out );
257
            p_out = NULL;
258
0
        }
259
0
    }
260
2.11k
    return p_out;
261
2.23k
}
262
263
static inline void packetizer_Header( packetizer_t *p_pack,
264
                                      const uint8_t *p_header, int i_header )
265
44.8k
{
266
44.8k
    block_t *p_init = block_Alloc( i_header );
267
44.8k
    if( !p_init )
268
0
        return;
269
270
44.8k
    memcpy( p_init->p_buffer, p_header, i_header );
271
272
44.8k
    block_t *p_pic;
273
44.8k
    while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
274
0
        block_Release( p_pic ); /* Should not happen (only sequence header) */
275
44.8k
    while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
276
0
        block_Release( p_pic );
277
278
    p_pack->b_synched = false;
279
44.8k
    block_BytestreamEmpty( &p_pack->bytestream );
280
44.8k
}
Unexecuted instantiation: a52.c:packetizer_Header
Unexecuted instantiation: dts.c:packetizer_Header
Unexecuted instantiation: flac.c:packetizer_Header
h264.c:packetizer_Header
Line
Count
Source
265
42.1k
{
266
42.1k
    block_t *p_init = block_Alloc( i_header );
267
42.1k
    if( !p_init )
268
0
        return;
269
270
42.1k
    memcpy( p_init->p_buffer, p_header, i_header );
271
272
42.1k
    block_t *p_pic;
273
42.1k
    while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
274
0
        block_Release( p_pic ); /* Should not happen (only sequence header) */
275
42.1k
    while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
276
0
        block_Release( p_pic );
277
278
    p_pack->b_synched = false;
279
42.1k
    block_BytestreamEmpty( &p_pack->bytestream );
280
42.1k
}
hevc.c:packetizer_Header
Line
Count
Source
265
633
{
266
633
    block_t *p_init = block_Alloc( i_header );
267
633
    if( !p_init )
268
0
        return;
269
270
633
    memcpy( p_init->p_buffer, p_header, i_header );
271
272
633
    block_t *p_pic;
273
633
    while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
274
0
        block_Release( p_pic ); /* Should not happen (only sequence header) */
275
633
    while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
276
0
        block_Release( p_pic );
277
278
    p_pack->b_synched = false;
279
633
    block_BytestreamEmpty( &p_pack->bytestream );
280
633
}
Unexecuted instantiation: mlp.c:packetizer_Header
Unexecuted instantiation: mpeg4audio.c:packetizer_Header
Unexecuted instantiation: mpeg4video.c:packetizer_Header
Unexecuted instantiation: mpegaudio.c:packetizer_Header
Unexecuted instantiation: mpegvideo.c:packetizer_Header
vc1.c:packetizer_Header
Line
Count
Source
265
2.05k
{
266
2.05k
    block_t *p_init = block_Alloc( i_header );
267
2.05k
    if( !p_init )
268
0
        return;
269
270
2.05k
    memcpy( p_init->p_buffer, p_header, i_header );
271
272
2.05k
    block_t *p_pic;
273
2.05k
    while( ( p_pic = packetizer_Packetize( p_pack, &p_init ) ) )
274
0
        block_Release( p_pic ); /* Should not happen (only sequence header) */
275
2.05k
    while( ( p_pic = packetizer_Packetize( p_pack, NULL ) ) )
276
0
        block_Release( p_pic );
277
278
    p_pack->b_synched = false;
279
2.05k
    block_BytestreamEmpty( &p_pack->bytestream );
280
2.05k
}
Unexecuted instantiation: mjpeg.c:packetizer_Header
281
282
#endif