diff options
Diffstat (limited to 'drivers/media')
-rw-r--r-- | drivers/media/test-drivers/vidtv/vidtv_encoder.h | 2 | ||||
-rw-r--r-- | drivers/media/test-drivers/vidtv/vidtv_mux.c | 42 | ||||
-rw-r--r-- | drivers/media/test-drivers/vidtv/vidtv_s302m.c | 56 | ||||
-rw-r--r-- | drivers/media/test-drivers/vidtv/vidtv_s302m.h | 2 |
4 files changed, 23 insertions, 79 deletions
diff --git a/drivers/media/test-drivers/vidtv/vidtv_encoder.h b/drivers/media/test-drivers/vidtv/vidtv_encoder.h index a7c99cafab4f..65d81daef4c3 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_encoder.h +++ b/drivers/media/test-drivers/vidtv/vidtv_encoder.h @@ -148,7 +148,7 @@ struct vidtv_encoder { __be16 es_pid; - void *(*encode)(struct vidtv_encoder *e, u64 elapsed_time_usecs); + void *(*encode)(struct vidtv_encoder *e); u32 (*clear)(struct vidtv_encoder *e); diff --git a/drivers/media/test-drivers/vidtv/vidtv_mux.c b/drivers/media/test-drivers/vidtv/vidtv_mux.c index 26a742c95c76..43b13aa3a8bc 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_mux.c +++ b/drivers/media/test-drivers/vidtv/vidtv_mux.c @@ -281,17 +281,11 @@ static u32 vidtv_mux_poll_encoders(struct vidtv_mux *m) struct vidtv_channel *cur_chnl = m->channels; struct vidtv_encoder *e = NULL; - u64 elapsed_time_usecs = jiffies_to_usecs(m->timing.current_jiffies - - m->timing.past_jiffies); - - elapsed_time_usecs = min_t(u64, elapsed_time_usecs, (u64)VIDTV_MAX_SLEEP_USECS); - while (cur_chnl) { e = cur_chnl->encoders; while (e) { - /* encode for 'elapsed_time_usecs' */ - e->encode(e, elapsed_time_usecs); + e->encode(e); /* get the TS packets into the mux buffer */ au_nbytes = vidtv_mux_packetize_access_units(m, e); nbytes += au_nbytes; @@ -337,38 +331,6 @@ static u32 vidtv_mux_pad_with_nulls(struct vidtv_mux *m, u32 npkts) return nbytes; } -static u32 vidtv_mux_check_mux_rate(struct vidtv_mux *m) -{ - /* - * attempt to maintain a constant mux rate, padding with null packets - * if needed - */ - - u32 nbytes = 0; /* the number of bytes written by this function */ - - u64 nbytes_expected; /* the number of bytes we should have written */ - u64 nbytes_streamed; /* the number of bytes we actually wrote */ - u32 num_null_pkts; /* number of null packets to bridge the gap */ - - u64 elapsed_time_msecs = jiffies_to_usecs(m->timing.current_jiffies - - m->timing.past_jiffies); - - elapsed_time_msecs = min(elapsed_time_msecs, (u64)VIDTV_MAX_SLEEP_USECS / 1000); - nbytes_expected = div64_u64(m->mux_rate_kbytes_sec * 1000, MSEC_PER_SEC); - nbytes_expected *= elapsed_time_msecs; - - nbytes_streamed = m->mux_buf_offset; - - if (nbytes_streamed < nbytes_expected) { - /* can't write half a packet: roundup to a 188 multiple */ - nbytes_expected = roundup(nbytes_expected - nbytes_streamed, TS_PACKET_LEN); - num_null_pkts = nbytes_expected / TS_PACKET_LEN; - nbytes += vidtv_mux_pad_with_nulls(m, num_null_pkts); - } - - return nbytes; -} - static void vidtv_mux_clear(struct vidtv_mux *m) { /* clear the packets currently in the mux */ @@ -400,7 +362,7 @@ static void vidtv_mux_tick(struct work_struct *work) nbytes += vidtv_mux_push_si(m); nbytes += vidtv_mux_poll_encoders(m); - nbytes += vidtv_mux_check_mux_rate(m); + nbytes += vidtv_mux_pad_with_nulls(m, 256); npkts = nbytes / TS_PACKET_LEN; diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.c b/drivers/media/test-drivers/vidtv/vidtv_s302m.c index 25b70594283b..a447ccbd68d5 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_s302m.c +++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.c @@ -40,6 +40,11 @@ #define S302M_BLOCK_SZ 192 #define S302M_SIN_LUT_NUM_ELEM 1024 +/* these are retrieved empirically from ffmpeg/libavcodec */ +#define FF_S302M_DEFAULT_NUM_FRAMES 1115 +#define FF_S302M_DEFAULT_PTS_INCREMENT 2090 +#define FF_S302M_DEFAULT_PTS_OFFSET 100000 + /* Used by the tone generator: number of samples for PI */ #define PI 180 @@ -189,7 +194,7 @@ static void vidtv_s302m_alloc_au(struct vidtv_encoder *e) } static void -vidtv_s302m_compute_sample_count_v(struct vidtv_encoder *e) +vidtv_s302m_compute_sample_count_from_video(struct vidtv_encoder *e) { struct vidtv_access_unit *au = e->access_units; struct vidtv_access_unit *sync_au = e->sync->access_units; @@ -208,33 +213,7 @@ vidtv_s302m_compute_sample_count_v(struct vidtv_encoder *e) } } -static void -vidtv_s302m_compute_sample_count(struct vidtv_encoder *e, - u64 elapsed_time_usecs) -{ - /* compute sample count for 'elapsed_time_usecs' */ - u32 sample_duration_usecs = USEC_PER_SEC / e->sampling_rate_hz; - struct vidtv_access_unit *au = e->access_units; - - au->num_samples = (u32)div64_u64(elapsed_time_usecs, sample_duration_usecs); -} - -static void vidtv_s302m_compute_pts(struct vidtv_encoder *e) -{ - u64 count = e->sample_count; - struct vidtv_access_unit *au = e->access_units; - - while (au) { - count += au->num_samples; - - au->pts = count * - CLOCK_UNIT_90KHZ / e->sampling_rate_hz; - - au = au->next; - } -} - -static void vidtv_s302m_compute_pts_v(struct vidtv_encoder *e) +static void vidtv_s302m_compute_pts_from_video(struct vidtv_encoder *e) { struct vidtv_access_unit *au = e->access_units; struct vidtv_access_unit *sync_au = e->sync->access_units; @@ -366,6 +345,7 @@ static u32 vidtv_s302m_write_h(struct vidtv_encoder *e, u32 p_sz) static void vidtv_s302m_write_frames(struct vidtv_encoder *e) { struct vidtv_access_unit *au = e->access_units; + struct vidtv_s302m_ctx *ctx = e->ctx; u32 nbytes_per_unit = 0; u32 nbytes = 0; u32 au_sz = 0; @@ -400,12 +380,13 @@ static void vidtv_s302m_write_frames(struct vidtv_encoder *e) au->offset = nbytes - nbytes_per_unit; nbytes_per_unit = 0; + ctx->au_count++; au = au->next; } } -static void *vidtv_s302m_encode(struct vidtv_encoder *e, u64 elapsed_time) +static void *vidtv_s302m_encode(struct vidtv_encoder *e) { /* * According to SMPTE 302M, an audio access unit is specified as those @@ -416,27 +397,26 @@ static void *vidtv_s302m_encode(struct vidtv_encoder *e, u64 elapsed_time) * * Assuming that it is also possible to send audio without any * associated video, as in a radio-like service, a single audio access unit - * is created with enough audio data for 'elapsed_time' - * The value of PTS is computed manually. + * is created with values for 'num_samples' and 'pts' taken empirically from + * ffmpeg */ - if (!elapsed_time) - goto out; + struct vidtv_s302m_ctx *ctx = e->ctx; vidtv_s302m_access_unit_destroy(e); vidtv_s302m_alloc_au(e); if (e->sync && e->sync->is_video_encoder) { - vidtv_s302m_compute_sample_count_v(e); - vidtv_s302m_compute_pts_v(e); + vidtv_s302m_compute_sample_count_from_video(e); + vidtv_s302m_compute_pts_from_video(e); } else { - vidtv_s302m_compute_sample_count(e, elapsed_time); - vidtv_s302m_compute_pts(e); + e->access_units->num_samples = FF_S302M_DEFAULT_NUM_FRAMES; + e->access_units->pts = (ctx->au_count * FF_S302M_DEFAULT_PTS_INCREMENT) + + FF_S302M_DEFAULT_PTS_OFFSET; } vidtv_s302m_write_frames(e); -out: return e->encoder_buf; } diff --git a/drivers/media/test-drivers/vidtv/vidtv_s302m.h b/drivers/media/test-drivers/vidtv/vidtv_s302m.h index 01ef47a812c8..eca5e3150ede 100644 --- a/drivers/media/test-drivers/vidtv/vidtv_s302m.h +++ b/drivers/media/test-drivers/vidtv/vidtv_s302m.h @@ -33,10 +33,12 @@ * struct vidtv_s302m_ctx - s302m encoder context. * @enc: A pointer to the containing encoder structure. * @frame_index: The current frame in a block + * @au_count: The total number of access units encoded up to now */ struct vidtv_s302m_ctx { struct vidtv_encoder *enc; u32 frame_index; + u32 au_count; }; /** |