VLC 4.0.0-dev
Loading...
Searching...
No Matches
h26x.h
Go to the documentation of this file.
1/**
2 * @file h26x.h
3 */
4/*****************************************************************************
5 * Copyright (C) 2022 VideoLabs, VLC authors and VideoLAN
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public License
9 * as published by the Free Software Foundation; either version 2.1
10 * of the License, or (at your option) any later version.
11 *
12 * This library 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
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ****************************************************************************/
21#include <vlc_common.h>
22#include <vlc_block.h>
23#include <vlc_strings.h>
24#include <vlc_codec.h>
25#include <vlc_demux.h>
26
27#include "rtp.h"
28#include "../live555_dtsgen.h"
29
30static const uint8_t annexbheader[] = { 0, 0, 0, 1 };
31
43
44static void rtp_h26x_clear(struct rtp_h26x_sys *sys)
45{
47 if(sys->xps)
48 block_Release(sys->xps);
49}
50
51static void rtp_h26x_init(struct rtp_h26x_sys *sys)
52{
53 sys->flags = 0;
54 sys->pts = VLC_TICK_INVALID;
55 sys->p_packets = NULL;
56 sys->pp_packets_next = &sys->p_packets;
57 sys->xps = NULL;
58 sys->es = NULL;
59 sys->p_packetizer = NULL;
60 dtsgen_Init(&sys->dtsgen);
61}
62
63static void h26x_extractbase64xps(const char *psz64,
64 const char *pszend,
65 void(*pf_output)(void *, uint8_t *, size_t),
66 void *outputsys)
67{
68 do
69 {
70 psz64 += strspn(psz64, " ");
71 uint8_t *xps = NULL;
72 size_t xpssz = vlc_b64_decode_binary(&xps, psz64);
73 pf_output(outputsys, xps, xpssz);
74 psz64 = strchr(psz64, ',');
75 if(psz64)
76 ++psz64;
77 } while(psz64 && *psz64 && psz64 < pszend);
78}
79
80static block_t * h26x_wrap_prefix(block_t *block, bool b_annexb)
81{
82 block = block_Realloc(block, 4, block->i_buffer);
83 if(block)
84 {
85 if(b_annexb)
86 memcpy(block->p_buffer, annexbheader, 4);
87 else
88 SetDWBE(block->p_buffer, block->i_buffer - 4);
89 }
90 return block;
91}
92
93static void h26x_add_xps(void *priv, uint8_t *xps, size_t xpssz)
94{
95 block_t *b = block_heap_Alloc(xps, xpssz);
96 if(!b || !(b = h26x_wrap_prefix(b, true)))
97 return;
98
99 block_t ***ppp_append = priv;
100 **ppp_append = b;
101 *ppp_append = &((**ppp_append)->p_next);
102}
103
104static block_t * h26x_fillextradata (const char *psz)
105{
106 block_t *xps = NULL;
107 block_t **pxps = &xps;
108 h26x_extractbase64xps(psz, strchr(psz, ';'), h26x_add_xps, &pxps);
109 if(xps)
110 xps = block_ChainGather(xps);
111 return xps;
112}
113
114static void h26x_output(struct rtp_h26x_sys *sys,
115 block_t *block,
116 vlc_tick_t pts, bool pcr, bool au_end)
117{
118 if(!block)
119 return;
120
121 if(sys->xps)
122 {
123 block_t *xps = sys->xps;
124 sys->xps = NULL;
125 h26x_output(sys, xps, pts, pcr, false);
126 }
127
129 dtsgen_Resync(&sys->dtsgen);
130
131 block->i_pts = pts;
132 block->i_dts = VLC_TICK_INVALID; /* RTP does not specify this */
133 if(au_end)
134 block->i_flags |= BLOCK_FLAG_AU_END;
135
136 block_t *p_out;
137 for(int i=0; i<(1+!!au_end); i++)
138 {
139 while((p_out = sys->p_packetizer->pf_packetize(sys->p_packetizer,
140 block ? &block : NULL)))
141 {
142 dtsgen_AddNextPTS(&sys->dtsgen, p_out->i_pts);
143 vlc_tick_t dts = dtsgen_GetDTS(&sys->dtsgen);
144 p_out->i_dts = dts;
145 vlc_rtp_es_send(sys->es, p_out);
146 }
147 block = NULL; // for drain iteration
148 }
149}
150
151static void h26x_output_blocks(struct rtp_h26x_sys *sys, bool b_annexb)
152{
153 if(!sys->p_packets)
154 return;
156 sys->p_packets = NULL;
157 sys->pp_packets_next = &sys->p_packets;
158 out = h26x_wrap_prefix(out, b_annexb);
159 h26x_output(sys, out, sys->pts, true, false);
160}
static void vlc_rtp_es_send(struct vlc_rtp_es *es, block_t *block)
Sends coded data for output.
Definition rtp.h:310
size_t vlc_b64_decode_binary(uint8_t **pp_dst, const char *psz_src)
Definition strings.c:461
static void rtp_h26x_init(struct rtp_h26x_sys *sys)
Definition h26x.h:51
static void h26x_extractbase64xps(const char *psz64, const char *pszend, void(*pf_output)(void *, uint8_t *, size_t), void *outputsys)
Definition h26x.h:63
static block_t * h26x_wrap_prefix(block_t *block, bool b_annexb)
Definition h26x.h:80
static void h26x_output_blocks(struct rtp_h26x_sys *sys, bool b_annexb)
Definition h26x.h:151
static void h26x_add_xps(void *priv, uint8_t *xps, size_t xpssz)
Definition h26x.h:93
static const uint8_t annexbheader[]
Definition h26x.h:30
static block_t * h26x_fillextradata(const char *psz)
Definition h26x.h:104
static void h26x_output(struct rtp_h26x_sys *sys, block_t *block, vlc_tick_t pts, bool pcr, bool au_end)
Definition h26x.h:114
static void rtp_h26x_clear(struct rtp_h26x_sys *sys)
Definition h26x.h:44
RTP demux module shared declarations.
Definition vlc_codec.h:102
vlc_frame_t *(* pf_packetize)(decoder_t *, vlc_frame_t **ppframe)
Definition vlc_codec.h:180
Definition h26x.h:33
decoder_t * p_packetizer
Definition h26x.h:40
block_t * p_packets
Definition h26x.h:37
struct vlc_rtp_es * es
Definition h26x.h:39
block_t * xps
Definition h26x.h:38
block_t ** pp_packets_next
Definition h26x.h:36
vlc_tick_t pts
Definition h26x.h:35
unsigned flags
Definition h26x.h:34
struct dtsgen_t dtsgen
Definition h26x.h:41
Definition vlc_frame.h:123
vlc_tick_t i_dts
Definition vlc_frame.h:135
uint8_t * p_buffer
Payload start.
Definition vlc_frame.h:126
vlc_tick_t i_pts
Definition vlc_frame.h:134
uint32_t i_flags
Definition vlc_frame.h:131
size_t i_buffer
Payload length.
Definition vlc_frame.h:127
RTP abstract output stream.
Definition rtp.h:289
#define block_ChainRelease
Definition vlc_block.h:99
#define BLOCK_FLAG_AU_END
Definition vlc_block.h:69
#define block_ChainGather
Definition vlc_block.h:102
#define BLOCK_FLAG_DISCONTINUITY
Definition vlc_block.h:58
#define block_Realloc
Definition vlc_block.h:86
#define block_heap_Alloc
Definition vlc_block.h:90
#define block_Release
Definition vlc_block.h:87
Decoder and encoder modules interface.
This file is a collection of common definitions and types.
static void SetDWBE(void *p, uint32_t dw)
Writes 32 bits in network byte order.
Definition vlc_common.h:1004
#define VLC_TICK_INVALID
Definition vlc_config.h:44
Demultiplexer modules interface.
Helper functions for nul-terminated strings.
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48