j2kpay: cleanup header construction

Use a simpler way of constructing the header that doesn't depend on
the endianness.
This commit is contained in:
Wim Taymans 2010-12-15 16:22:54 +01:00
parent 984564150f
commit 744472d2ad

View file

@ -86,47 +86,18 @@ enum
PROP_LAST
};
/*
* RtpJ2KHeader:
* @tp: type (0 progressive, 1 odd field, 2 even field)
* @MHF: Main Header Flag
* @mh_id: Main Header Identification
* @T: Tile field invalidation flag
* @priority: priority
* @tile number: the tile number of the payload
* @reserved: set to 0
* @fragment offset: the byte offset of the current payload
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |tp |MHF|mh_id|T| priority | tile number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |reserved | fragment offset |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
typedef struct
{
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
guint T:1;
guint mh_id:3;
guint MHF:2;
guint tp:2;
#elif G_BYTE_ORDER == G_BIG_ENDIAN
guint tp:2;
guint MHF:2;
guint mh_id:3;
guint T:1;
#else
#error "G_BYTE_ORDER should be big or little endian."
#endif
guint priority:8;
guint tile:16;
guint reserved:8;
guint offset:24;
} RtpJ2KHeader;
#define HEADER_SIZE sizeof(RtpJ2KHeader)
#define HEADER_SIZE 8
static void gst_rtp_j2k_pay_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
@ -388,7 +359,6 @@ gst_rtp_j2k_pay_handle_buffer (GstBaseRTPPayload * basepayload,
state.header.T = 1; /* invalid tile */
state.header.priority = 255; /* always 255 for now */
state.header.tile = 0; /* no tile number */
state.header.reserved = 0;
state.bitstream = FALSE;
state.n_tiles = 0;
state.next_sot = 0;
@ -493,14 +463,34 @@ gst_rtp_j2k_pay_handle_buffer (GstBaseRTPPayload * basepayload,
gst_rtp_buffer_set_marker (outbuf, TRUE);
}
/* copy the header and push the packet */
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
state.header.offset = ((offset & 0x0000FF) << 16) |
((offset & 0xFF0000) >> 16) | (offset & 0x00FF00);
#else
state.header.offset = offset;
#endif
memcpy (header, &state.header, HEADER_SIZE);
/*
* RtpJ2KHeader:
* @tp: type (0 progressive, 1 odd field, 2 even field)
* @MHF: Main Header Flag
* @mh_id: Main Header Identification
* @T: Tile field invalidation flag
* @priority: priority
* @tile number: the tile number of the payload
* @reserved: set to 0
* @fragment offset: the byte offset of the current payload
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |tp |MHF|mh_id|T| priority | tile number |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* |reserved | fragment offset |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
header[0] = (state.header.tp << 6) | (state.header.MHF << 4) |
(state.header.mh_id << 1) | state.header.T;
header[1] = state.header.priority;
header[2] = state.header.tile >> 8;
header[3] = state.header.tile & 0xff;
header[4] = 0;
header[5] = state.header.offset >> 16;
header[6] = (state.header.offset >> 8) & 0xff;
header[7] = state.header.offset & 0xff;
if (pay->buffer_list) {
GstBuffer *paybuf;