-
Notifications
You must be signed in to change notification settings - Fork 6
/
h264_sei.cpp
94 lines (78 loc) · 1.97 KB
/
h264_sei.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Created by monktan on 2020/10/21.
//
#include "bs.h"
#include "h264_stream.h"
#include "h264_sei.h"
#include <stdio.h>
#include <stdlib.h> // malloc
#include <string.h> // memset
sei_t* sei_new()
{
sei_t* s = (sei_t*)malloc(sizeof(sei_t));
memset(s, 0, sizeof(sei_t));
s->payload = NULL;
return s;
}
void sei_free(sei_t* s)
{
if ( s->payload != NULL ) free(s->payload);
free(s);
}
void read_sei_end_bits(h264_stream_t* h, bs_t* b )
{
// if the message doesn't end at a byte border
if ( !bs_byte_aligned( b ) )
{
if ( !bs_read_u1( b ) ) fprintf(stderr, "WARNING: bit_equal_to_one is 0!!!!\n");
while ( ! bs_byte_aligned( b ) )
{
if ( bs_read_u1( b ) ) fprintf(stderr, "WARNING: bit_equal_to_zero is 1!!!!\n");
}
}
read_rbsp_trailing_bits(h, b);
}
static void read_user_data_unregistered(h264_stream_t* h, bs_t* b, int payloadSize)
{
sei_t* s = h->sei;
s->payload = (uint8_t*)malloc(payloadSize);
int i;
// uuid_iso_iec_11578 todo...
for (i = 0; i < 16; i++)
s->payload[i] = bs_read_u(b, 8);
for (i = 16; i < payloadSize; i++)
s->payload[i] = bs_read_u(b, 8);
}
// D.1 SEI payload syntax
// todo����ͬ��sei���ṹ�岻ͬ����ֱ�
void read_sei_payload(h264_stream_t* h, bs_t* b, int payloadType, int payloadSize)
{
sei_t* s = h->sei;
switch (payloadType)
{
case 0:
break;
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
read_user_data_unregistered(h, b, payloadSize);
break;
default:
break;
}
read_sei_end_bits(h, b);
}
// D.1 SEI payload syntax
void write_sei_payload(h264_stream_t* h, bs_t* b, int payloadType, int payloadSize)
{
sei_t* s = h->sei;
int i;
for ( i = 0; i < s->payloadSize; i++ )
bs_write_u(b, 8, s->payload[i]);
}