/src/vlc/modules/packetizer/hxxx_ep3b.h
Line | Count | Source |
1 | | /***************************************************************************** |
2 | | * hxxx_ep3b.h |
3 | | ***************************************************************************** |
4 | | * Copyright (C) 2014-2015 VLC authors and VideoLAN |
5 | | * 2018 VideoLabs |
6 | | * |
7 | | * This program is free software; you can redistribute it and/or modify it |
8 | | * under the terms of the GNU Lesser General Public License as published by |
9 | | * the Free Software Foundation; either version 2.1 of the License, or |
10 | | * (at your option) any later version. |
11 | | * |
12 | | * This program 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 |
15 | | * GNU Lesser General Public License for more details. |
16 | | * |
17 | | * You should have received a copy of the GNU Lesser General Public License |
18 | | * along with this program; if not, write to the Free Software Foundation, |
19 | | * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. |
20 | | *****************************************************************************/ |
21 | | #include <vlc_bits.h> |
22 | | |
23 | | static inline const uint8_t *hxxx_ep3b_to_rbsp( const uint8_t *p, const uint8_t *end, unsigned *pi_prev, size_t i_count ) |
24 | 37.2M | { |
25 | 94.7M | for( size_t i=0; i<i_count; i++ ) |
26 | 60.9M | { |
27 | 60.9M | if( ++p >= end ) |
28 | 3.49M | return p; |
29 | | |
30 | 57.5M | *pi_prev = (*pi_prev << 1) | (!*p); |
31 | | |
32 | 57.5M | if( *p == 0x03 && |
33 | 685k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ |
34 | 661k | { |
35 | 661k | if( (*pi_prev & 0x06) == 0x06 ) |
36 | 151k | { |
37 | 151k | ++p; |
38 | 151k | *pi_prev = !*p; |
39 | 151k | } |
40 | 661k | } |
41 | 57.5M | } |
42 | 33.8M | return p; |
43 | 37.2M | } hxxx_sei.c:hxxx_ep3b_to_rbsp Line | Count | Source | 24 | 8.56M | { | 25 | 34.7M | for( size_t i=0; i<i_count; i++ ) | 26 | 26.5M | { | 27 | 26.5M | if( ++p >= end ) | 28 | 386k | return p; | 29 | | | 30 | 26.1M | *pi_prev = (*pi_prev << 1) | (!*p); | 31 | | | 32 | 26.1M | if( *p == 0x03 && | 33 | 239k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ | 34 | 220k | { | 35 | 220k | if( (*pi_prev & 0x06) == 0x06 ) | 36 | 17.3k | { | 37 | 17.3k | ++p; | 38 | 17.3k | *pi_prev = !*p; | 39 | 17.3k | } | 40 | 220k | } | 41 | 26.1M | } | 42 | 8.17M | return p; | 43 | 8.56M | } |
h264_nal.c:hxxx_ep3b_to_rbsp Line | Count | Source | 24 | 4.04M | { | 25 | 12.6M | for( size_t i=0; i<i_count; i++ ) | 26 | 8.78M | { | 27 | 8.78M | if( ++p >= end ) | 28 | 131k | return p; | 29 | | | 30 | 8.65M | *pi_prev = (*pi_prev << 1) | (!*p); | 31 | | | 32 | 8.65M | if( *p == 0x03 && | 33 | 25.9k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ | 34 | 23.1k | { | 35 | 23.1k | if( (*pi_prev & 0x06) == 0x06 ) | 36 | 3.18k | { | 37 | 3.18k | ++p; | 38 | 3.18k | *pi_prev = !*p; | 39 | 3.18k | } | 40 | 23.1k | } | 41 | 8.65M | } | 42 | 3.91M | return p; | 43 | 4.04M | } |
h264_slice.c:hxxx_ep3b_to_rbsp Line | Count | Source | 24 | 4.43M | { | 25 | 8.63M | for( size_t i=0; i<i_count; i++ ) | 26 | 4.53M | { | 27 | 4.53M | if( ++p >= end ) | 28 | 340k | return p; | 29 | | | 30 | 4.19M | *pi_prev = (*pi_prev << 1) | (!*p); | 31 | | | 32 | 4.19M | if( *p == 0x03 && | 33 | 123k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ | 34 | 122k | { | 35 | 122k | if( (*pi_prev & 0x06) == 0x06 ) | 36 | 2.15k | { | 37 | 2.15k | ++p; | 38 | 2.15k | *pi_prev = !*p; | 39 | 2.15k | } | 40 | 122k | } | 41 | 4.19M | } | 42 | 4.09M | return p; | 43 | 4.43M | } |
hevc_nal.c:hxxx_ep3b_to_rbsp Line | Count | Source | 24 | 19.4M | { | 25 | 37.0M | for( size_t i=0; i<i_count; i++ ) | 26 | 20.2M | { | 27 | 20.2M | if( ++p >= end ) | 28 | 2.63M | return p; | 29 | | | 30 | 17.6M | *pi_prev = (*pi_prev << 1) | (!*p); | 31 | | | 32 | 17.6M | if( *p == 0x03 && | 33 | 289k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ | 34 | 287k | { | 35 | 287k | if( (*pi_prev & 0x06) == 0x06 ) | 36 | 128k | { | 37 | 128k | ++p; | 38 | 128k | *pi_prev = !*p; | 39 | 128k | } | 40 | 287k | } | 41 | 17.6M | } | 42 | 16.7M | return p; | 43 | 19.4M | } |
Line | Count | Source | 24 | 838k | { | 25 | 1.67M | for( size_t i=0; i<i_count; i++ ) | 26 | 840k | { | 27 | 840k | if( ++p >= end ) | 28 | 3.78k | return p; | 29 | | | 30 | 836k | *pi_prev = (*pi_prev << 1) | (!*p); | 31 | | | 32 | 836k | if( *p == 0x03 && | 33 | 6.79k | ( p + 1 ) != end ) /* Never escape sequence if no next byte */ | 34 | 6.79k | { | 35 | 6.79k | if( (*pi_prev & 0x06) == 0x06 ) | 36 | 417 | { | 37 | 417 | ++p; | 38 | 417 | *pi_prev = !*p; | 39 | 417 | } | 40 | 6.79k | } | 41 | 836k | } | 42 | 834k | return p; | 43 | 838k | } |
|
44 | | |
45 | | #if 0 |
46 | | /* Discards emulation prevention three bytes */ |
47 | | static inline uint8_t * hxxx_ep3b_to_rbsp(const uint8_t *p_src, size_t i_src, size_t *pi_ret) |
48 | | { |
49 | | uint8_t *p_dst; |
50 | | if(!p_src || !(p_dst = malloc(i_src))) |
51 | | return NULL; |
52 | | |
53 | | size_t j = 0; |
54 | | for (size_t i = 0; i < i_src; i++) { |
55 | | if (i < i_src - 3 && |
56 | | p_src[i] == 0 && p_src[i+1] == 0 && p_src[i+2] == 3) { |
57 | | p_dst[j++] = 0; |
58 | | p_dst[j++] = 0; |
59 | | i += 2; |
60 | | continue; |
61 | | } |
62 | | p_dst[j++] = p_src[i]; |
63 | | } |
64 | | *pi_ret = j; |
65 | | return p_dst; |
66 | | } |
67 | | #endif |
68 | | |
69 | | /* vlc_bits's bs_t forward callback for stripping emulation prevention three bytes */ |
70 | | struct hxxx_bsfw_ep3b_ctx_s |
71 | | { |
72 | | unsigned i_prev; |
73 | | size_t i_bytepos; |
74 | | }; |
75 | | |
76 | | static void hxxx_bsfw_ep3b_ctx_init( struct hxxx_bsfw_ep3b_ctx_s *ctx ) |
77 | 4.80M | { |
78 | 4.80M | ctx->i_prev = 0; |
79 | 4.80M | ctx->i_bytepos = 0; |
80 | 4.80M | } hxxx_sei.c:hxxx_bsfw_ep3b_ctx_init Line | Count | Source | 77 | 405k | { | 78 | 405k | ctx->i_prev = 0; | 79 | 405k | ctx->i_bytepos = 0; | 80 | 405k | } |
h264_nal.c:hxxx_bsfw_ep3b_ctx_init Line | Count | Source | 77 | 365k | { | 78 | 365k | ctx->i_prev = 0; | 79 | 365k | ctx->i_bytepos = 0; | 80 | 365k | } |
h264_slice.c:hxxx_bsfw_ep3b_ctx_init Line | Count | Source | 77 | 823k | { | 78 | 823k | ctx->i_prev = 0; | 79 | 823k | ctx->i_bytepos = 0; | 80 | 823k | } |
hevc_nal.c:hxxx_bsfw_ep3b_ctx_init Line | Count | Source | 77 | 3.17M | { | 78 | 3.17M | ctx->i_prev = 0; | 79 | 3.17M | ctx->i_bytepos = 0; | 80 | 3.17M | } |
vc1.c:hxxx_bsfw_ep3b_ctx_init Line | Count | Source | 77 | 31.8k | { | 78 | 31.8k | ctx->i_prev = 0; | 79 | 31.8k | ctx->i_bytepos = 0; | 80 | 31.8k | } |
|
81 | | |
82 | | static size_t hxxx_bsfw_byte_forward_ep3b( bs_t *s, size_t i_count ) |
83 | 48.6M | { |
84 | 48.6M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; |
85 | 48.6M | if( s->p == NULL ) |
86 | 4.80M | { |
87 | 4.80M | s->p = s->p_start; |
88 | 4.80M | ctx->i_bytepos = 1; |
89 | 4.80M | return 1; |
90 | 4.80M | } |
91 | | |
92 | 43.8M | if( s->p >= s->p_end ) |
93 | 6.51M | return 0; |
94 | | |
95 | 37.2M | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); |
96 | 37.2M | ctx->i_bytepos += i_count; |
97 | 37.2M | return i_count; |
98 | 43.8M | } hxxx_sei.c:hxxx_bsfw_byte_forward_ep3b Line | Count | Source | 83 | 9.88M | { | 84 | 9.88M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 85 | 9.88M | if( s->p == NULL ) | 86 | 405k | { | 87 | 405k | s->p = s->p_start; | 88 | 405k | ctx->i_bytepos = 1; | 89 | 405k | return 1; | 90 | 405k | } | 91 | | | 92 | 9.48M | if( s->p >= s->p_end ) | 93 | 916k | return 0; | 94 | | | 95 | 8.56M | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); | 96 | 8.56M | ctx->i_bytepos += i_count; | 97 | 8.56M | return i_count; | 98 | 9.48M | } |
h264_nal.c:hxxx_bsfw_byte_forward_ep3b Line | Count | Source | 83 | 4.93M | { | 84 | 4.93M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 85 | 4.93M | if( s->p == NULL ) | 86 | 365k | { | 87 | 365k | s->p = s->p_start; | 88 | 365k | ctx->i_bytepos = 1; | 89 | 365k | return 1; | 90 | 365k | } | 91 | | | 92 | 4.57M | if( s->p >= s->p_end ) | 93 | 530k | return 0; | 94 | | | 95 | 4.04M | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); | 96 | 4.04M | ctx->i_bytepos += i_count; | 97 | 4.04M | return i_count; | 98 | 4.57M | } |
h264_slice.c:hxxx_bsfw_byte_forward_ep3b Line | Count | Source | 83 | 6.02M | { | 84 | 6.02M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 85 | 6.02M | if( s->p == NULL ) | 86 | 823k | { | 87 | 823k | s->p = s->p_start; | 88 | 823k | ctx->i_bytepos = 1; | 89 | 823k | return 1; | 90 | 823k | } | 91 | | | 92 | 5.19M | if( s->p >= s->p_end ) | 93 | 762k | return 0; | 94 | | | 95 | 4.43M | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); | 96 | 4.43M | ctx->i_bytepos += i_count; | 97 | 4.43M | return i_count; | 98 | 5.19M | } |
hevc_nal.c:hxxx_bsfw_byte_forward_ep3b Line | Count | Source | 83 | 26.8M | { | 84 | 26.8M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 85 | 26.8M | if( s->p == NULL ) | 86 | 3.17M | { | 87 | 3.17M | s->p = s->p_start; | 88 | 3.17M | ctx->i_bytepos = 1; | 89 | 3.17M | return 1; | 90 | 3.17M | } | 91 | | | 92 | 23.6M | if( s->p >= s->p_end ) | 93 | 4.27M | return 0; | 94 | | | 95 | 19.4M | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); | 96 | 19.4M | ctx->i_bytepos += i_count; | 97 | 19.4M | return i_count; | 98 | 23.6M | } |
vc1.c:hxxx_bsfw_byte_forward_ep3b Line | Count | Source | 83 | 891k | { | 84 | 891k | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 85 | 891k | if( s->p == NULL ) | 86 | 31.8k | { | 87 | 31.8k | s->p = s->p_start; | 88 | 31.8k | ctx->i_bytepos = 1; | 89 | 31.8k | return 1; | 90 | 31.8k | } | 91 | | | 92 | 859k | if( s->p >= s->p_end ) | 93 | 21.3k | return 0; | 94 | | | 95 | 838k | s->p = (uint8_t*) hxxx_ep3b_to_rbsp( s->p, s->p_end, &ctx->i_prev, i_count ); | 96 | 838k | ctx->i_bytepos += i_count; | 97 | 838k | return i_count; | 98 | 859k | } |
|
99 | | |
100 | | static size_t hxxx_bsfw_byte_pos_ep3b( const bs_t *s ) |
101 | 3.65M | { |
102 | 3.65M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; |
103 | 3.65M | return ctx->i_bytepos; |
104 | 3.65M | } hxxx_sei.c:hxxx_bsfw_byte_pos_ep3b Line | Count | Source | 101 | 3.65M | { | 102 | 3.65M | struct hxxx_bsfw_ep3b_ctx_s *ctx = s->p_priv; | 103 | 3.65M | return ctx->i_bytepos; | 104 | 3.65M | } |
Unexecuted instantiation: h264_nal.c:hxxx_bsfw_byte_pos_ep3b Unexecuted instantiation: h264_slice.c:hxxx_bsfw_byte_pos_ep3b Unexecuted instantiation: hevc_nal.c:hxxx_bsfw_byte_pos_ep3b Unexecuted instantiation: vc1.c:hxxx_bsfw_byte_pos_ep3b |
105 | | |
106 | | static const bs_byte_callbacks_t hxxx_bsfw_ep3b_callbacks = |
107 | | { |
108 | | hxxx_bsfw_byte_forward_ep3b, |
109 | | hxxx_bsfw_byte_pos_ep3b, |
110 | | }; |