archrelease: copy trunk to testing-any
[arch-packages.git] / vlc / repos / extra-x86_64 / c2dd4bfe.patch
blobbdd5921a2e019ed34c31bd6108857924c64069ad
1 From c2dd4bfefe079e49db1789eb76be3885e4fc31b4 Mon Sep 17 00:00:00 2001
2 From: Francois Cartegnie <fcvlcdev@free.fr>
3 Date: Mon, 7 Nov 2022 15:02:57 +0100
4 Subject: [PATCH] packetizer: flac: fix CRC from emulated sync
6 also skips some memcpy
8 refs #27454 #27477
10 (cherry picked from commit c14b5aa6a7bd3aa25fa951e2b4136aff70f5702a)
11 ---
12 modules/packetizer/flac.c | 13 +++++++++++--
13 1 file changed, 11 insertions(+), 2 deletions(-)
15 diff --git a/modules/packetizer/flac.c b/modules/packetizer/flac.c
16 index 8998f5dac0f..bfb504f004e 100644
17 --- a/modules/packetizer/flac.c
18 +++ b/modules/packetizer/flac.c
19 @@ -78,6 +78,7 @@ struct decoder_sys_t
21 size_t i_last_frame_size;
22 uint16_t crc;
23 + size_t i_buf_offset; /* in final buffer before crc check / validation / retry */
24 size_t i_buf;
25 uint8_t *p_buf;
27 @@ -386,6 +387,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
28 p_sys->headerinfo = headerinfo;
29 p_sys->i_state = STATE_NEXT_SYNC;
30 p_sys->i_offset = FLAC_FRAME_SIZE_MIN;
31 + p_sys->i_buf_offset = 0;
32 p_sys->crc = 0;
34 /* We have to read until next frame sync code to compute current frame size
35 @@ -461,6 +463,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
36 block_SkipBytes( &p_sys->bytestream, FLAC_HEADER_SIZE_MAX + 2 );
37 block_BytestreamFlush( &p_sys->bytestream );
38 p_sys->crc = 0;
39 + p_sys->i_buf_offset = 0;
40 p_sys->i_offset = 0;
41 p_sys->i_state = STATE_NOSYNC;
42 p_sys->i_next_block_flags |= BLOCK_FLAG_DISCONTINUITY;
43 @@ -484,10 +487,12 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
46 /* Copy from previous sync point up to to current (offset) */
47 - block_PeekOffsetBytes( &p_sys->bytestream, 0, p_sys->p_buf, p_sys->i_offset );
48 + block_PeekOffsetBytes( &p_sys->bytestream, p_sys->i_buf_offset,
49 + &p_sys->p_buf[p_sys->i_buf_offset],
50 + p_sys->i_offset - p_sys->i_buf_offset );
52 /* update crc to include this data chunk */
53 - for( size_t i = 0; i < p_sys->i_offset - 2; i++ )
54 + for( size_t i = p_sys->i_buf_offset; i < p_sys->i_offset - 2; i++ )
55 p_sys->crc = flac_crc16( p_sys->crc, p_sys->p_buf[i] );
57 uint16_t stream_crc = GetWBE(&p_sys->p_buf[p_sys->i_offset - 2]);
58 @@ -497,6 +502,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
59 /* Add the 2 last bytes which were not the CRC sum, and go for next sync point */
60 p_sys->crc = flac_crc16( p_sys->crc, p_sys->p_buf[p_sys->i_offset - 2] );
61 p_sys->crc = flac_crc16( p_sys->crc, p_sys->p_buf[p_sys->i_offset - 1] );
62 + p_sys->i_buf_offset = p_sys->i_offset;
63 p_sys->i_offset += 1;
64 p_sys->i_state = !pp_block ? STATE_NOSYNC : STATE_NEXT_SYNC;
65 break; /* continue */
66 @@ -513,6 +519,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
67 block_BytestreamFlush( &p_sys->bytestream );
68 p_sys->i_offset = 0;
69 p_sys->crc = 0;
70 + p_sys->i_buf_offset = 0;
72 if( block_BytestreamRemaining(&p_sys->bytestream) > 0 || pp_block == NULL /* drain */)
73 p_sys->i_state = STATE_SEND_DATA;
74 @@ -553,6 +560,7 @@ static block_t *Packetize(decoder_t *p_dec, block_t **pp_block)
75 else
76 free( p_sys->p_buf );
78 + p_sys->i_buf_offset = 0;
79 p_sys->i_buf = 0;
80 p_sys->p_buf = NULL;
81 p_sys->i_offset = 0;
82 @@ -587,6 +595,7 @@ static int Open(vlc_object_t *p_this)
83 p_sys->b_stream_info = false;
84 p_sys->i_last_frame_size = FLAC_FRAME_SIZE_MIN;
85 p_sys->headerinfo.i_pts = VLC_TS_INVALID;
86 + p_sys->i_buf_offset = 0;
87 p_sys->i_buf = 0;
88 p_sys->p_buf = NULL;
89 p_sys->i_next_block_flags = 0;
90 --
91 GitLab