1 /*
2  *  Stream plumbing, connects individual streaming components to each other
3  *  Copyright (C) 2008 Andreas Öman
4  *
5  *  This program is free software: you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation, either version 3 of the License, or
8  *  (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, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef STREAMING_H_
20 #define STREAMING_H_
21 
22 #include "packet.h"
23 #include "htsmsg.h"
24 #include "service.h"
25 
26 
27 typedef struct streaming_start_component {
28   int ssc_index;
29   int ssc_type;
30   char ssc_lang[4];
31   uint8_t ssc_audio_type;
32   uint8_t ssc_audio_version;
33   uint16_t ssc_composition_id;
34   uint16_t ssc_ancillary_id;
35   uint16_t ssc_pid;
36   int16_t ssc_width;
37   int16_t ssc_height;
38   int16_t ssc_aspect_num;
39   int16_t ssc_aspect_den;
40   uint8_t ssc_sri;
41   uint8_t ssc_ext_sri;
42   uint8_t ssc_channels;
43   uint8_t ssc_disabled;
44   uint8_t ssc_muxer_disabled;
45 
46   pktbuf_t *ssc_gh;
47 
48   int ssc_frameduration;
49 
50 } streaming_start_component_t;
51 
52 
53 
54 typedef struct streaming_start {
55   int ss_refcount;
56 
57   int ss_num_components;
58 
59   source_info_t ss_si;
60 
61   uint16_t ss_pcr_pid;
62   uint16_t ss_pmt_pid;
63   uint16_t ss_service_id;
64 
65   streaming_start_component_t ss_components[0];
66 
67 } streaming_start_t;
68 
69 
70 /**
71  *
72  */
73 void streaming_pad_init(streaming_pad_t *sp);
74 
75 void streaming_target_init(streaming_target_t *st,
76 			   streaming_ops_t *ops, void *opaque,
77 			   int reject_filter);
78 
79 void streaming_queue_init
80   (streaming_queue_t *sq, int reject_filter, size_t maxsize);
81 
82 void streaming_queue_clear(struct streaming_message_queue *q);
83 
84 void streaming_queue_deinit(streaming_queue_t *sq);
85 
86 void streaming_queue_remove(streaming_queue_t *sq, streaming_message_t *sm);
87 
88 void streaming_target_connect(streaming_pad_t *sp, streaming_target_t *st);
89 
90 void streaming_target_disconnect(streaming_pad_t *sp, streaming_target_t *st);
91 
92 void streaming_pad_deliver(streaming_pad_t *sp, streaming_message_t *sm);
93 
94 void streaming_msg_free(streaming_message_t *sm);
95 
96 streaming_message_t *streaming_msg_clone(streaming_message_t *src);
97 
98 streaming_message_t *streaming_msg_create(streaming_message_type_t type);
99 
100 streaming_message_t *streaming_msg_create_data(streaming_message_type_t type,
101 					       void *data);
102 
103 streaming_message_t *streaming_msg_create_code(streaming_message_type_t type,
104 					       int code);
105 
106 streaming_message_t *streaming_msg_create_pkt(th_pkt_t *pkt);
107 
108 static inline void
streaming_target_deliver(streaming_target_t * st,streaming_message_t * sm)109 streaming_target_deliver(streaming_target_t *st, streaming_message_t *sm)
110   { st->st_ops.st_cb(st->st_opaque, sm); }
111 
112 void streaming_target_deliver2(streaming_target_t *st, streaming_message_t *sm);
113 
streaming_start_ref(streaming_start_t * ss)114 static inline void streaming_start_ref(streaming_start_t *ss)
115 {
116   atomic_add(&ss->ss_refcount, 1);
117 }
118 
119 void streaming_start_unref(streaming_start_t *ss);
120 
121 streaming_start_t *streaming_start_copy(const streaming_start_t *src);
122 
123 static inline int
streaming_pad_probe_type(streaming_pad_t * sp,streaming_message_type_t smt)124 streaming_pad_probe_type(streaming_pad_t *sp, streaming_message_type_t smt)
125 {
126   return (sp->sp_reject_filter & SMT_TO_MASK(smt)) == 0;
127 }
128 
129 const char *streaming_code2txt(int code);
130 
131 streaming_start_component_t *streaming_start_component_find_by_index(streaming_start_t *ss, int idx);
132 
133 void streaming_init(void);
134 void streaming_done(void);
135 
136 #endif /* STREAMING_H_ */
137