[vlc-devel] [PATCH] rtp: JPEG packetization

Samuel Pitoiset samuel.pitoiset at gmail.com
Tue Aug 28 19:37:40 CEST 2012


On Tue, Aug 28, 2012 at 7:36 PM, Samuel Pitoiset
<samuel.pitoiset at gmail.com> wrote:
> ---
>  modules/stream_out/rtpfmt.c | 46 ++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 45 insertions(+), 1 deletion(-)
>
> diff --git a/modules/stream_out/rtpfmt.c b/modules/stream_out/rtpfmt.c
> index 79ae441..36418c6 100644
> --- a/modules/stream_out/rtpfmt.c
> +++ b/modules/stream_out/rtpfmt.c
> @@ -53,6 +53,7 @@ static int rtp_packetize_g726_24 (sout_stream_id_t *, block_t *);
>  static int rtp_packetize_g726_32 (sout_stream_id_t *, block_t *);
>  static int rtp_packetize_g726_40 (sout_stream_id_t *, block_t *);
>  static int rtp_packetize_xiph (sout_stream_id_t *, block_t *);
> +static int rtp_packetize_jpeg (sout_stream_id_t *, block_t *);
>
>  #define XIPH_IDENT (0)
>
> @@ -511,7 +512,11 @@ int rtp_get_fmt( vlc_object_t *obj, es_format_t *p_fmt, const char *mux,
>              rtp_fmt->clock_rate = 1000;
>              rtp_fmt->pf_packetize = rtp_packetize_t140;
>              break;
> -
> +        case VLC_CODEC_MJPG:
> +            rtp_fmt->payload_type = 26;
> +            rtp_fmt->ptname = "JPEG";
> +            rtp_fmt->pf_packetize = rtp_packetize_jpeg;
> +            break;
>          default:
>              msg_Err( obj, "cannot add this stream (unsupported "
>                       "codec: %4.4s)", (char*)&p_fmt->i_codec );
> @@ -660,6 +665,45 @@ static int rtp_packetize_xiph( sout_stream_id_t *id, block_t *in )
>      return VLC_SUCCESS;
>  }
>
> +/* rfc2435 */
> +static int rtp_packetize_jpeg( sout_stream_id_t *id, block_t *in )
> +{
> +    int      i_max   = rtp_mtu (id) - 6; /* payload max in one packet */
> +    int      i_count = ( in->i_buffer + i_max - 1 ) / i_max;
> +
> +    uint8_t  *p_data = in->p_buffer;
> +    int      i_data  = in->i_buffer;
> +    uint32_t i_off   = 0; /* fragment offset of the current JPEG frame */
> +
> +    for( int i = 0; i < i_count; i++ )
> +    {
> +        int i_payload = __MIN( i_max, i_data );
> +        block_t *out  = block_Alloc( 20 + i_payload );
> +
> +        /* Type-specific:8, Fragment Offset:24, Type:8, Q:8, Width:8, Height:8 */
> +        uint64_t header = ((uint64_t)0 << 56) | ((uint64_t)i_off << 32) |
> +                          (0 << 24) | (0 << 16) | (39 << 8) | 29;

The width and the height of frames shouldn't be hardcoded but I don't
know how to access to these values.... hint?

> +
> +        /* rtp common header */
> +        rtp_packetize_common( id, out, (i == i_count - 1) ? 1 : 0, in->i_dts);
> +
> +        SetQWBE( out->p_buffer + 12, header);
> +        memcpy( &out->p_buffer[20], p_data, i_payload );
> +
> +        out->i_buffer = 20 + i_payload;
> +        out->i_dts    = in->i_dts + i * in->i_length / i_count;
> +        out->i_length = in->i_length / i_count;
> +
> +        rtp_packetize_send( id, out );
> +
> +        p_data += i_payload;
> +        i_data -= i_payload;
> +        i_off  += i_payload;
> +    }
> +
> +    return VLC_SUCCESS;
> +}
> +
>  static int rtp_packetize_mpa( sout_stream_id_t *id, block_t *in )
>  {
>      int     i_max   = rtp_mtu (id) - 4; /* payload max in one packet */
> --
> 1.7.11.3
>



-- 
Best regards,
Samuel Pitoiset.



More information about the vlc-devel mailing list