Lines Matching +full:0 +full:m
34 *vidtv_mux_get_pid_ctx(struct vidtv_mux *m, u16 pid) in vidtv_mux_get_pid_ctx() argument
38 hash_for_each_possible(m->pid_ctx, ctx, h, pid) in vidtv_mux_get_pid_ctx()
45 *vidtv_mux_create_pid_ctx_once(struct vidtv_mux *m, u16 pid) in vidtv_mux_create_pid_ctx_once() argument
49 ctx = vidtv_mux_get_pid_ctx(m, pid); in vidtv_mux_create_pid_ctx_once()
58 ctx->cc = 0; in vidtv_mux_create_pid_ctx_once()
59 hash_add(m->pid_ctx, &ctx->h, pid); in vidtv_mux_create_pid_ctx_once()
64 static void vidtv_mux_pid_ctx_destroy(struct vidtv_mux *m) in vidtv_mux_pid_ctx_destroy() argument
70 hash_for_each_safe(m->pid_ctx, bkt, tmp, ctx, h) { in vidtv_mux_pid_ctx_destroy()
76 static int vidtv_mux_pid_ctx_init(struct vidtv_mux *m) in vidtv_mux_pid_ctx_init() argument
78 struct vidtv_psi_table_pat_program *p = m->si.pat->program; in vidtv_mux_pid_ctx_init()
81 hash_init(m->pid_ctx); in vidtv_mux_pid_ctx_init()
83 if (!vidtv_mux_create_pid_ctx_once(m, m->pcr_pid)) in vidtv_mux_pid_ctx_init()
86 if (!vidtv_mux_create_pid_ctx_once(m, TS_NULL_PACKET_PID)) in vidtv_mux_pid_ctx_init()
89 if (!vidtv_mux_create_pid_ctx_once(m, VIDTV_PAT_PID)) in vidtv_mux_pid_ctx_init()
92 if (!vidtv_mux_create_pid_ctx_once(m, VIDTV_SDT_PID)) in vidtv_mux_pid_ctx_init()
95 if (!vidtv_mux_create_pid_ctx_once(m, VIDTV_NIT_PID)) in vidtv_mux_pid_ctx_init()
98 if (!vidtv_mux_create_pid_ctx_once(m, VIDTV_EIT_PID)) in vidtv_mux_pid_ctx_init()
104 vidtv_mux_create_pid_ctx_once(m, pid); in vidtv_mux_pid_ctx_init()
108 return 0; in vidtv_mux_pid_ctx_init()
111 vidtv_mux_pid_ctx_destroy(m); in vidtv_mux_pid_ctx_init()
115 static void vidtv_mux_update_clk(struct vidtv_mux *m) in vidtv_mux_update_clk() argument
120 m->timing.past_jiffies = m->timing.current_jiffies; in vidtv_mux_update_clk()
121 m->timing.current_jiffies = get_jiffies_64(); in vidtv_mux_update_clk()
123 elapsed_time = jiffies_to_usecs(m->timing.current_jiffies - in vidtv_mux_update_clk()
124 m->timing.past_jiffies); in vidtv_mux_update_clk()
127 m->timing.clk += (CLOCK_UNIT_27MHZ / USEC_PER_SEC) * elapsed_time; in vidtv_mux_update_clk()
130 static u32 vidtv_mux_push_si(struct vidtv_mux *m) in vidtv_mux_push_si() argument
133 .buf = m->mux_buf, in vidtv_mux_push_si()
134 .buf_sz = m->mux_buf_sz, in vidtv_mux_push_si()
135 .pat = m->si.pat, in vidtv_mux_push_si()
138 .buf = m->mux_buf, in vidtv_mux_push_si()
139 .buf_sz = m->mux_buf_sz, in vidtv_mux_push_si()
140 .pcr_pid = m->pcr_pid, in vidtv_mux_push_si()
143 .buf = m->mux_buf, in vidtv_mux_push_si()
144 .buf_sz = m->mux_buf_sz, in vidtv_mux_push_si()
145 .sdt = m->si.sdt, in vidtv_mux_push_si()
148 .buf = m->mux_buf, in vidtv_mux_push_si()
149 .buf_sz = m->mux_buf_sz, in vidtv_mux_push_si()
150 .nit = m->si.nit, in vidtv_mux_push_si()
154 .buf = m->mux_buf, in vidtv_mux_push_si()
155 .buf_sz = m->mux_buf_sz, in vidtv_mux_push_si()
156 .eit = m->si.eit, in vidtv_mux_push_si()
158 u32 initial_offset = m->mux_buf_offset; in vidtv_mux_push_si()
168 pat_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_PAT_PID); in vidtv_mux_push_si()
169 sdt_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_SDT_PID); in vidtv_mux_push_si()
170 nit_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_NIT_PID); in vidtv_mux_push_si()
171 eit_ctx = vidtv_mux_get_pid_ctx(m, VIDTV_EIT_PID); in vidtv_mux_push_si()
173 pat_args.offset = m->mux_buf_offset; in vidtv_mux_push_si()
176 m->mux_buf_offset += vidtv_psi_pat_write_into(&pat_args); in vidtv_mux_push_si()
178 for (i = 0; i < m->si.pat->num_pmt; ++i) { in vidtv_mux_push_si()
179 pmt_pid = vidtv_psi_pmt_get_pid(m->si.pmt_secs[i], in vidtv_mux_push_si()
180 m->si.pat); in vidtv_mux_push_si()
183 dev_warn_ratelimited(m->dev, in vidtv_mux_push_si()
188 pmt_ctx = vidtv_mux_get_pid_ctx(m, pmt_pid); in vidtv_mux_push_si()
190 pmt_args.offset = m->mux_buf_offset; in vidtv_mux_push_si()
191 pmt_args.pmt = m->si.pmt_secs[i]; in vidtv_mux_push_si()
196 m->mux_buf_offset += vidtv_psi_pmt_write_into(&pmt_args); in vidtv_mux_push_si()
199 sdt_args.offset = m->mux_buf_offset; in vidtv_mux_push_si()
202 m->mux_buf_offset += vidtv_psi_sdt_write_into(&sdt_args); in vidtv_mux_push_si()
204 nit_args.offset = m->mux_buf_offset; in vidtv_mux_push_si()
207 m->mux_buf_offset += vidtv_psi_nit_write_into(&nit_args); in vidtv_mux_push_si()
209 eit_args.offset = m->mux_buf_offset; in vidtv_mux_push_si()
212 m->mux_buf_offset += vidtv_psi_eit_write_into(&eit_args); in vidtv_mux_push_si()
214 nbytes = m->mux_buf_offset - initial_offset; in vidtv_mux_push_si()
216 m->num_streamed_si++; in vidtv_mux_push_si()
221 static u32 vidtv_mux_push_pcr(struct vidtv_mux *m) in vidtv_mux_push_pcr() argument
225 u32 nbytes = 0; in vidtv_mux_push_pcr()
227 ctx = vidtv_mux_get_pid_ctx(m, m->pcr_pid); in vidtv_mux_push_pcr()
228 args.dest_buf = m->mux_buf; in vidtv_mux_push_pcr()
229 args.pid = m->pcr_pid; in vidtv_mux_push_pcr()
230 args.buf_sz = m->mux_buf_sz; in vidtv_mux_push_pcr()
234 args.pcr = m->timing.clk; in vidtv_mux_push_pcr()
237 m->mux_buf_offset += nbytes; in vidtv_mux_push_pcr()
239 m->num_streamed_pcr++; in vidtv_mux_push_pcr()
244 static bool vidtv_mux_should_push_pcr(struct vidtv_mux *m) in vidtv_mux_should_push_pcr() argument
248 if (m->num_streamed_pcr == 0) in vidtv_mux_should_push_pcr()
251 next_pcr_at = m->timing.start_jiffies + in vidtv_mux_should_push_pcr()
252 usecs_to_jiffies(m->num_streamed_pcr * in vidtv_mux_should_push_pcr()
253 m->timing.pcr_period_usecs); in vidtv_mux_should_push_pcr()
255 return time_after64(m->timing.current_jiffies, next_pcr_at); in vidtv_mux_should_push_pcr()
258 static bool vidtv_mux_should_push_si(struct vidtv_mux *m) in vidtv_mux_should_push_si() argument
262 if (m->num_streamed_si == 0) in vidtv_mux_should_push_si()
265 next_si_at = m->timing.start_jiffies + in vidtv_mux_should_push_si()
266 usecs_to_jiffies(m->num_streamed_si * in vidtv_mux_should_push_si()
267 m->timing.si_period_usecs); in vidtv_mux_should_push_si()
269 return time_after64(m->timing.current_jiffies, next_si_at); in vidtv_mux_should_push_si()
272 static u32 vidtv_mux_packetize_access_units(struct vidtv_mux *m, in vidtv_mux_packetize_access_units() argument
276 .dest_buf = m->mux_buf, in vidtv_mux_packetize_access_units()
277 .dest_buf_sz = m->mux_buf_sz, in vidtv_mux_packetize_access_units()
285 u32 initial_offset = m->mux_buf_offset; in vidtv_mux_packetize_access_units()
287 u32 nbytes = 0; in vidtv_mux_packetize_access_units()
290 /* see SMPTE 302M clause 6.4 */ in vidtv_mux_packetize_access_units()
296 pid_ctx = vidtv_mux_create_pid_ctx_once(m, be16_to_cpu(e->es_pid)); in vidtv_mux_packetize_access_units()
303 args.dest_offset = m->mux_buf_offset; in vidtv_mux_packetize_access_units()
305 args.pcr = m->timing.clk; in vidtv_mux_packetize_access_units()
307 m->mux_buf_offset += vidtv_pes_write_into(&args); in vidtv_mux_packetize_access_units()
318 nbytes = m->mux_buf_offset - initial_offset; in vidtv_mux_packetize_access_units()
322 static u32 vidtv_mux_poll_encoders(struct vidtv_mux *m) in vidtv_mux_poll_encoders() argument
324 struct vidtv_channel *cur_chnl = m->channels; in vidtv_mux_poll_encoders()
326 u32 nbytes = 0; in vidtv_mux_poll_encoders()
335 au_nbytes = vidtv_mux_packetize_access_units(m, e); in vidtv_mux_poll_encoders()
337 m->mux_buf_offset += au_nbytes; in vidtv_mux_poll_encoders()
349 static u32 vidtv_mux_pad_with_nulls(struct vidtv_mux *m, u32 npkts) in vidtv_mux_pad_with_nulls() argument
352 .dest_buf = m->mux_buf, in vidtv_mux_pad_with_nulls()
353 .buf_sz = m->mux_buf_sz, in vidtv_mux_pad_with_nulls()
354 .dest_offset = m->mux_buf_offset, in vidtv_mux_pad_with_nulls()
356 u32 initial_offset = m->mux_buf_offset; in vidtv_mux_pad_with_nulls()
361 ctx = vidtv_mux_get_pid_ctx(m, TS_NULL_PACKET_PID); in vidtv_mux_pad_with_nulls()
365 for (i = 0; i < npkts; ++i) { in vidtv_mux_pad_with_nulls()
366 m->mux_buf_offset += vidtv_ts_null_write_into(args); in vidtv_mux_pad_with_nulls()
367 args.dest_offset = m->mux_buf_offset; in vidtv_mux_pad_with_nulls()
370 nbytes = m->mux_buf_offset - initial_offset; in vidtv_mux_pad_with_nulls()
374 dev_err_ratelimited(m->dev, "%d != %d\n", in vidtv_mux_pad_with_nulls()
380 static void vidtv_mux_clear(struct vidtv_mux *m) in vidtv_mux_clear() argument
383 memset(m->mux_buf, 0, m->mux_buf_sz * sizeof(*m->mux_buf)); in vidtv_mux_clear()
385 m->mux_buf_offset = 0; in vidtv_mux_clear()
391 struct vidtv_mux *m = container_of(work, in vidtv_mux_tick() local
394 struct dtv_frontend_properties *c = &m->fe->dtv_property_cache; in vidtv_mux_tick()
395 u32 tot_bits = 0; in vidtv_mux_tick()
399 while (m->streaming) { in vidtv_mux_tick()
400 nbytes = 0; in vidtv_mux_tick()
402 vidtv_mux_update_clk(m); in vidtv_mux_tick()
404 if (vidtv_mux_should_push_pcr(m)) in vidtv_mux_tick()
405 nbytes += vidtv_mux_push_pcr(m); in vidtv_mux_tick()
407 if (vidtv_mux_should_push_si(m)) in vidtv_mux_tick()
408 nbytes += vidtv_mux_push_si(m); in vidtv_mux_tick()
410 nbytes += vidtv_mux_poll_encoders(m); in vidtv_mux_tick()
411 nbytes += vidtv_mux_pad_with_nulls(m, 256); in vidtv_mux_tick()
417 dev_err_ratelimited(m->dev, "Misaligned buffer\n"); in vidtv_mux_tick()
419 if (m->on_new_packets_available_cb) in vidtv_mux_tick()
420 m->on_new_packets_available_cb(m->priv, in vidtv_mux_tick()
421 m->mux_buf, in vidtv_mux_tick()
424 vidtv_mux_clear(m); in vidtv_mux_tick()
433 c->pre_bit_count.stat[0].uvalue = nbytes * 8; in vidtv_mux_tick()
434 c->post_bit_count.stat[0].uvalue = nbytes * 8; in vidtv_mux_tick()
435 c->block_count.stat[0].uvalue += npkts; in vidtv_mux_tick()
449 c->pre_bit_error.stat[0].uvalue++; in vidtv_mux_tick()
457 void vidtv_mux_start_thread(struct vidtv_mux *m) in vidtv_mux_start_thread() argument
459 if (m->streaming) { in vidtv_mux_start_thread()
460 dev_warn_ratelimited(m->dev, "Already streaming. Skipping.\n"); in vidtv_mux_start_thread()
464 m->streaming = true; in vidtv_mux_start_thread()
465 m->timing.start_jiffies = get_jiffies_64(); in vidtv_mux_start_thread()
466 schedule_work(&m->mpeg_thread); in vidtv_mux_start_thread()
469 void vidtv_mux_stop_thread(struct vidtv_mux *m) in vidtv_mux_stop_thread() argument
471 if (m->streaming) { in vidtv_mux_stop_thread()
472 m->streaming = false; /* thread will quit */ in vidtv_mux_stop_thread()
473 cancel_work_sync(&m->mpeg_thread); in vidtv_mux_stop_thread()
481 struct vidtv_mux *m; in vidtv_mux_init() local
483 m = kzalloc(sizeof(*m), GFP_KERNEL); in vidtv_mux_init()
484 if (!m) in vidtv_mux_init()
487 m->dev = dev; in vidtv_mux_init()
488 m->fe = fe; in vidtv_mux_init()
489 m->timing.pcr_period_usecs = args->pcr_period_usecs; in vidtv_mux_init()
490 m->timing.si_period_usecs = args->si_period_usecs; in vidtv_mux_init()
492 m->mux_rate_kbytes_sec = args->mux_rate_kbytes_sec; in vidtv_mux_init()
494 m->on_new_packets_available_cb = args->on_new_packets_available_cb; in vidtv_mux_init()
496 m->mux_buf = vzalloc(args->mux_buf_sz); in vidtv_mux_init()
497 if (!m->mux_buf) in vidtv_mux_init()
500 m->mux_buf_sz = args->mux_buf_sz; in vidtv_mux_init()
502 m->pcr_pid = args->pcr_pid; in vidtv_mux_init()
503 m->transport_stream_id = args->transport_stream_id; in vidtv_mux_init()
504 m->priv = args->priv; in vidtv_mux_init()
505 m->network_id = args->network_id; in vidtv_mux_init()
506 m->network_name = kstrdup(args->network_name, GFP_KERNEL); in vidtv_mux_init()
507 if (!m->network_name) in vidtv_mux_init()
510 m->timing.current_jiffies = get_jiffies_64(); in vidtv_mux_init()
513 m->channels = args->channels; in vidtv_mux_init()
515 if (vidtv_channels_init(m) < 0) in vidtv_mux_init()
519 if (vidtv_channel_si_init(m) < 0) in vidtv_mux_init()
522 INIT_WORK(&m->mpeg_thread, vidtv_mux_tick); in vidtv_mux_init()
524 if (vidtv_mux_pid_ctx_init(m) < 0) in vidtv_mux_init()
527 return m; in vidtv_mux_init()
530 vidtv_channel_si_destroy(m); in vidtv_mux_init()
532 vidtv_channels_destroy(m); in vidtv_mux_init()
534 kfree(m->network_name); in vidtv_mux_init()
536 vfree(m->mux_buf); in vidtv_mux_init()
538 kfree(m); in vidtv_mux_init()
542 void vidtv_mux_destroy(struct vidtv_mux *m) in vidtv_mux_destroy() argument
544 vidtv_mux_stop_thread(m); in vidtv_mux_destroy()
545 vidtv_mux_pid_ctx_destroy(m); in vidtv_mux_destroy()
546 vidtv_channel_si_destroy(m); in vidtv_mux_destroy()
547 vidtv_channels_destroy(m); in vidtv_mux_destroy()
548 kfree(m->network_name); in vidtv_mux_destroy()
549 vfree(m->mux_buf); in vidtv_mux_destroy()
550 kfree(m); in vidtv_mux_destroy()