/src/vlc/modules/packetizer/hxxx_nal.h
Line | Count | Source (jump to first uncovered line) |
1 | | /***************************************************************************** |
2 | | * hxxx_nal.h: Common helpers for AVC/HEVC NALU |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2014-2015 VLC authors and VideoLAN |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify it |
7 | | * under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation; either version 2.1 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
19 | | *****************************************************************************/ |
20 | | #ifndef HXXX_NAL_H |
21 | | #define HXXX_NAL_H |
22 | | |
23 | | #include <stdbit.h> |
24 | | |
25 | | #include <vlc_common.h> |
26 | | #include <vlc_es.h> |
27 | | #include "startcode_helper.h" |
28 | | |
29 | | static const uint8_t annexb_startcode4[] = { 0x00, 0x00, 0x00, 0x01 }; |
30 | 37.8k | #define annexb_startcode3 (&annexb_startcode4[1]) |
31 | | |
32 | | /* strips any AnnexB startcode [0] 0 0 1 */ |
33 | | static inline bool hxxx_strip_AnnexB_startcode( const uint8_t **pp_data, size_t *pi_data ) |
34 | 2.84M | { |
35 | 2.84M | unsigned bitflow = 0; |
36 | 2.84M | const uint8_t *p_data = *pp_data; |
37 | 2.84M | size_t i_data = *pi_data; |
38 | | |
39 | 11.3M | while( i_data && p_data[0] <= 1 ) |
40 | 11.3M | { |
41 | 11.3M | bitflow = (bitflow << 1) | (!p_data[0]); |
42 | 11.3M | p_data++; |
43 | 11.3M | i_data--; |
44 | 11.3M | if( !(bitflow & 0x01) ) |
45 | 2.84M | { |
46 | 2.84M | if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */ |
47 | 2.84M | { |
48 | 2.84M | *pi_data = i_data; |
49 | 2.84M | *pp_data = p_data; |
50 | 2.84M | return true; |
51 | 2.84M | } |
52 | 0 | return false; |
53 | 2.84M | } |
54 | 11.3M | } |
55 | 0 | return false; |
56 | 2.84M | } h264.c:hxxx_strip_AnnexB_startcode Line | Count | Source | 34 | 776k | { | 35 | 776k | unsigned bitflow = 0; | 36 | 776k | const uint8_t *p_data = *pp_data; | 37 | 776k | size_t i_data = *pi_data; | 38 | | | 39 | 3.10M | while( i_data && p_data[0] <= 1 ) | 40 | 3.10M | { | 41 | 3.10M | bitflow = (bitflow << 1) | (!p_data[0]); | 42 | 3.10M | p_data++; | 43 | 3.10M | i_data--; | 44 | 3.10M | if( !(bitflow & 0x01) ) | 45 | 776k | { | 46 | 776k | if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */ | 47 | 776k | { | 48 | 776k | *pi_data = i_data; | 49 | 776k | *pp_data = p_data; | 50 | 776k | return true; | 51 | 776k | } | 52 | 0 | return false; | 53 | 776k | } | 54 | 3.10M | } | 55 | 0 | return false; | 56 | 776k | } |
hxxx_sei.c:hxxx_strip_AnnexB_startcode Line | Count | Source | 34 | 109k | { | 35 | 109k | unsigned bitflow = 0; | 36 | 109k | const uint8_t *p_data = *pp_data; | 37 | 109k | size_t i_data = *pi_data; | 38 | | | 39 | 438k | while( i_data && p_data[0] <= 1 ) | 40 | 438k | { | 41 | 438k | bitflow = (bitflow << 1) | (!p_data[0]); | 42 | 438k | p_data++; | 43 | 438k | i_data--; | 44 | 438k | if( !(bitflow & 0x01) ) | 45 | 109k | { | 46 | 109k | if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */ | 47 | 109k | { | 48 | 109k | *pi_data = i_data; | 49 | 109k | *pp_data = p_data; | 50 | 109k | return true; | 51 | 109k | } | 52 | 0 | return false; | 53 | 109k | } | 54 | 438k | } | 55 | 0 | return false; | 56 | 109k | } |
Unexecuted instantiation: h264_nal.c:hxxx_strip_AnnexB_startcode Unexecuted instantiation: h264_slice.c:hxxx_strip_AnnexB_startcode hevc.c:hxxx_strip_AnnexB_startcode Line | Count | Source | 34 | 1.95M | { | 35 | 1.95M | unsigned bitflow = 0; | 36 | 1.95M | const uint8_t *p_data = *pp_data; | 37 | 1.95M | size_t i_data = *pi_data; | 38 | | | 39 | 7.83M | while( i_data && p_data[0] <= 1 ) | 40 | 7.83M | { | 41 | 7.83M | bitflow = (bitflow << 1) | (!p_data[0]); | 42 | 7.83M | p_data++; | 43 | 7.83M | i_data--; | 44 | 7.83M | if( !(bitflow & 0x01) ) | 45 | 1.95M | { | 46 | 1.95M | if( (bitflow & 0x06) == 0x06 ) /* there was at least 2 leading zeros */ | 47 | 1.95M | { | 48 | 1.95M | *pi_data = i_data; | 49 | 1.95M | *pp_data = p_data; | 50 | 1.95M | return true; | 51 | 1.95M | } | 52 | 0 | return false; | 53 | 1.95M | } | 54 | 7.83M | } | 55 | 0 | return false; | 56 | 1.95M | } |
Unexecuted instantiation: hevc_nal.c:hxxx_strip_AnnexB_startcode Unexecuted instantiation: vc1.c:hxxx_strip_AnnexB_startcode |
57 | | |
58 | | /* Declarations */ |
59 | | |
60 | | typedef struct |
61 | | { |
62 | | const uint8_t *p_head; |
63 | | const uint8_t *p_tail; |
64 | | uint8_t i_nal_length_size; |
65 | | } hxxx_iterator_ctx_t; |
66 | | |
67 | | static inline void hxxx_iterator_init( hxxx_iterator_ctx_t *p_ctx, const uint8_t *p_data, size_t i_data, |
68 | | uint8_t i_nal_length_size ) |
69 | 0 | { |
70 | 0 | p_ctx->p_head = p_data; |
71 | 0 | p_ctx->p_tail = p_data + i_data; |
72 | 0 | if( stdc_has_single_bit(i_nal_length_size) && i_nal_length_size <= 4 ) |
73 | 0 | p_ctx->i_nal_length_size = i_nal_length_size; |
74 | 0 | else |
75 | 0 | p_ctx->i_nal_length_size = 0; |
76 | 0 | } Unexecuted instantiation: h264.c:hxxx_iterator_init Unexecuted instantiation: hxxx_sei.c:hxxx_iterator_init Unexecuted instantiation: h264_nal.c:hxxx_iterator_init Unexecuted instantiation: h264_slice.c:hxxx_iterator_init Unexecuted instantiation: hevc.c:hxxx_iterator_init Unexecuted instantiation: hevc_nal.c:hxxx_iterator_init Unexecuted instantiation: vc1.c:hxxx_iterator_init |
77 | | |
78 | | static inline bool hxxx_iterate_next( hxxx_iterator_ctx_t *p_ctx, const uint8_t **pp_start, size_t *pi_size ) |
79 | 0 | { |
80 | 0 | if( p_ctx->i_nal_length_size == 0 ) |
81 | 0 | return false; |
82 | 0 |
|
83 | 0 | if( p_ctx->p_tail - p_ctx->p_head < p_ctx->i_nal_length_size ) |
84 | 0 | return false; |
85 | 0 |
|
86 | 0 | uint32_t i_nal_size = 0; |
87 | 0 | for( uint8_t i=0; i < p_ctx->i_nal_length_size ; i++ ) |
88 | 0 | i_nal_size = (i_nal_size << 8) | *p_ctx->p_head++; |
89 | 0 |
|
90 | 0 | if( i_nal_size > (size_t)(p_ctx->p_tail - p_ctx->p_head) ) |
91 | 0 | return false; |
92 | 0 |
|
93 | 0 | *pp_start = p_ctx->p_head; |
94 | 0 | *pi_size = i_nal_size; |
95 | 0 | p_ctx->p_head += i_nal_size; |
96 | 0 |
|
97 | 0 | return true; |
98 | 0 | } Unexecuted instantiation: h264.c:hxxx_iterate_next Unexecuted instantiation: hxxx_sei.c:hxxx_iterate_next Unexecuted instantiation: h264_nal.c:hxxx_iterate_next Unexecuted instantiation: h264_slice.c:hxxx_iterate_next Unexecuted instantiation: hevc.c:hxxx_iterate_next Unexecuted instantiation: hevc_nal.c:hxxx_iterate_next Unexecuted instantiation: vc1.c:hxxx_iterate_next |
99 | | |
100 | | static inline bool hxxx_annexb_iterate_next( hxxx_iterator_ctx_t *p_ctx, const uint8_t **pp_start, size_t *pi_size ) |
101 | 0 | { |
102 | 0 | if( !p_ctx->p_head ) |
103 | 0 | return false; |
104 | | |
105 | 0 | p_ctx->p_head = startcode_FindAnnexB( p_ctx->p_head, p_ctx->p_tail ); |
106 | 0 | if( !p_ctx->p_head ) |
107 | 0 | return false; |
108 | | |
109 | 0 | const uint8_t *p_end = startcode_FindAnnexB( p_ctx->p_head + 3, p_ctx->p_tail ); |
110 | 0 | if( !p_end ) |
111 | 0 | p_end = p_ctx->p_tail; |
112 | | |
113 | | /* fix 3 to 4 startcode offset and strip any trailing zeros */ |
114 | 0 | while( p_end > p_ctx->p_head && p_end[-1] == 0 ) |
115 | 0 | p_end--; |
116 | |
|
117 | 0 | *pp_start = p_ctx->p_head; |
118 | 0 | *pi_size = p_end - p_ctx->p_head; |
119 | 0 | p_ctx->p_head = p_end; |
120 | |
|
121 | 0 | return hxxx_strip_AnnexB_startcode( pp_start, pi_size ); |
122 | 0 | } Unexecuted instantiation: h264.c:hxxx_annexb_iterate_next Unexecuted instantiation: hxxx_sei.c:hxxx_annexb_iterate_next Unexecuted instantiation: h264_nal.c:hxxx_annexb_iterate_next Unexecuted instantiation: h264_slice.c:hxxx_annexb_iterate_next Unexecuted instantiation: hevc.c:hxxx_annexb_iterate_next Unexecuted instantiation: hevc_nal.c:hxxx_annexb_iterate_next Unexecuted instantiation: vc1.c:hxxx_annexb_iterate_next |
123 | | |
124 | | /* Takes any AnnexB NAL buffer and converts it to prefixed size (AVC/HEVC) */ |
125 | | block_t *hxxx_AnnexB_to_xVC( block_t *p_block, uint8_t i_nal_length_size ); |
126 | | |
127 | | #endif // HXXX_NAL_H |