1 /*
2 mediastreamer2 library - modular sound and video processing and streaming
3 Copyright (C) 2006  Simon MORLAT (simon.morlat@linphone.org)
4 
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18 */
19 
20 
21 #ifndef VP8RTPFMT_H
22 #define VP8RTPFMT_H
23 
24 #include <mediastreamer2/mscommon.h>
25 #include <mediastreamer2/msfilter.h>
26 #include <mediastreamer2/msqueue.h>
27 #include <mediastreamer2/msvideo.h>
28 
29 /**
30  * This file declares an API useful to pack/unpack a VP8 stream in RTP packets
31  * as described in draft-ietf-payload-vp8-11
32  * (http://tools.ietf.org/html/draft-ietf-payload-vp8-11)
33  */
34 
35 #ifdef __cplusplus
36 extern "C"{
37 #endif
38 
39 	typedef enum Vp8RtpFmtErrorCode {
40 		Vp8RtpFmtOk = 0,
41 		Vp8RtpFmtInvalidPayloadDescriptor = -1,
42 		Vp8RtpFmtIncompleteFrame = -2,
43 		Vp8RtpFmtInvalidFrame = -3
44 	} Vp8RtpFmtErrorCode;
45 
46 	typedef struct Vp8RtpFmtPayloadDescriptor {
47 		uint16_t pictureid;
48 		uint8_t pid;
49 		uint8_t tl0picidx;
50 		uint8_t tid;
51 		uint8_t keyidx;
52 		bool_t extended_control_bits_present;
53 		bool_t non_reference_frame;
54 		bool_t start_of_partition;
55 		bool_t pictureid_present;
56 		bool_t tl0picidx_present;
57 		bool_t tid_present;
58 		bool_t keyidx_present;
59 		bool_t layer_sync;
60 	} Vp8RtpFmtPayloadDescriptor;
61 
62 	typedef struct Vp8RtpFmtPacket {
63 		mblk_t *m;
64 		Vp8RtpFmtPayloadDescriptor *pd;
65 		Vp8RtpFmtErrorCode error;
66 		bool_t cseq_inconsistency;
67 	} Vp8RtpFmtPacket;
68 
69 	typedef struct Vp8RtpFmtPartition {
70 		MSList *packets_list;
71 		mblk_t *m;
72 		size_t size;
73 		bool_t has_start;
74 		bool_t has_marker;
75 		bool_t outputted;
76 	} Vp8RtpFmtPartition;
77 
78 	typedef struct Vp8RtpFmtFramePartitionsInfo {
79 		uint32_t partition_sizes[8];
80 		uint8_t nb_partitions;
81 	} Vp8RtpFmtFramePartitionsInfo;
82 
83 	typedef struct Vp8RtpFmtFrame {
84 		Vp8RtpFmtFramePartitionsInfo partitions_info;
85 		Vp8RtpFmtPartition *partitions[9];
86 		Vp8RtpFmtErrorCode error;
87 		uint16_t pictureid;
88 		bool_t pictureid_present;
89 		bool_t unnumbered_partitions;
90 		bool_t keyframe;
91 		bool_t reference;
92 		bool_t outputted;
93 		bool_t discarded;
94 	} Vp8RtpFmtFrame;
95 
96 	typedef struct Vp8RtpFmtFrameInfo {
97 		uint16_t pictureid;
98 		bool_t pictureid_present;
99 		bool_t keyframe;
100 	} Vp8RtpFmtFrameInfo;
101 
102 
103 	typedef struct Vp8RtpFmtUnpackerCtx {
104 		MSFilter *filter;
105 		MSList *frames_list;
106 		MSList *non_processed_packets_list;
107 		MSVideoSize video_size;
108 		uint32_t last_ts;
109 		uint16_t ref_cseq;
110 		bool_t avpf_enabled;
111 		bool_t freeze_on_error;
112 		bool_t output_partitions;
113 		bool_t waiting_for_reference_frame;
114 		bool_t error_notified;
115 		bool_t valid_keyframe_received;
116 		bool_t initialized_last_ts;
117 		bool_t initialized_ref_cseq;
118 	} Vp8RtpFmtUnpackerCtx;
119 
120 	typedef struct Vp8RtpFmtPackerCtx {
121 		MSQueue *output_queue;
122 		MSFactory *factory;
123 	} Vp8RtpFmtPackerCtx;
124 
125 
126 	void vp8rtpfmt_packer_init(Vp8RtpFmtPackerCtx *ctx);
127 	void vp8rtpfmt_packer_uninit(Vp8RtpFmtPackerCtx *ctx);
128 	void vp8rtpfmt_packer_process(Vp8RtpFmtPackerCtx *ctx, MSList *in, MSQueue *out, MSFactory *f);
129 
130 	void vp8rtpfmt_unpacker_init(Vp8RtpFmtUnpackerCtx *ctx, MSFilter *f, bool_t avpf_enabled, bool_t freeze_on_error, bool_t output_partitions);
131 	void vp8rtpfmt_unpacker_uninit(Vp8RtpFmtUnpackerCtx *ctx);
132 	void vp8rtpfmt_unpacker_feed(Vp8RtpFmtUnpackerCtx *ctx, MSQueue *in);
133 	int vp8rtpfmt_unpacker_get_frame(Vp8RtpFmtUnpackerCtx *ctx, MSQueue *out, Vp8RtpFmtFrameInfo *frame_info);
134 	uint32_t vp8rtpfmt_unpacker_calc_extended_cseq(Vp8RtpFmtUnpackerCtx *ctx, uint16_t cseq);
135 	void vp8rtpfmt_send_rpsi(Vp8RtpFmtUnpackerCtx *ctx, uint16_t pictureid);
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 
141 #endif /* VP8RTPFMT_H */
142