mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 23:14:46 +00:00
rtpj2k: move common code to shared header, code clean up
https://bugzilla.gnome.org/show_bug.cgi?id=745187
This commit is contained in:
parent
82c2a5cbf8
commit
d2765be120
5 changed files with 82 additions and 66 deletions
49
gst/rtp/gstrtpj2kcommon.h
Normal file
49
gst/rtp/gstrtpj2kcommon.h
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* GStreamer
|
||||
* Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GST_RTP_J2K_COMMON_H__
|
||||
#define __GST_RTP_J2K_COMMON_H__
|
||||
|
||||
|
||||
/*
|
||||
* GstRtpJ2KMarker:
|
||||
* @GST_J2K_MARKER: Prefix for JPEG 2000 marker
|
||||
* @GST_J2K_MARKER_SOC: Start of Codestream
|
||||
* @GST_J2K_MARKER_SOT: Start of tile
|
||||
* @GST_J2K_MARKER_EOC: End of Codestream
|
||||
*
|
||||
* Identifers for markers in JPEG 2000 codestreams
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GST_J2K_MARKER = 0xFF,
|
||||
GST_J2K_MARKER_SOC = 0x4F,
|
||||
GST_J2K_MARKER_SOT = 0x90,
|
||||
GST_J2K_MARKER_SOP = 0x91,
|
||||
GST_J2K_MARKER_EPH = 0x92,
|
||||
GST_J2K_MARKER_SOD = 0x93,
|
||||
GST_J2K_MARKER_EOC = 0xD9
|
||||
} GstRtpJ2KMarker;
|
||||
|
||||
|
||||
#define GST_RTP_J2K_HEADER_SIZE 8
|
||||
|
||||
|
||||
#endif /* __GST_RTP_J2K_COMMON_H__ */
|
|
@ -36,6 +36,7 @@
|
|||
#include <gst/video/video.h>
|
||||
|
||||
#include <string.h>
|
||||
#include "gstrtpj2kcommon.h"
|
||||
#include "gstrtpj2kdepay.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
|
@ -58,16 +59,6 @@ GST_STATIC_PAD_TEMPLATE ("sink",
|
|||
"clock-rate = (int) 90000, " "encoding-name = (string) \"JPEG2000\"")
|
||||
);
|
||||
|
||||
typedef enum
|
||||
{
|
||||
J2K_MARKER = 0xFF,
|
||||
J2K_MARKER_SOC = 0x4F,
|
||||
J2K_MARKER_SOT = 0x90,
|
||||
J2K_MARKER_SOP = 0x91,
|
||||
J2K_MARKER_SOD = 0x93,
|
||||
J2K_MARKER_EOC = 0xD9
|
||||
} RtpJ2KMarker;
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
|
@ -313,10 +304,10 @@ gst_rtp_j2k_depay_flush_tile (GstRTPBaseDepayload * depayload)
|
|||
if (map.size < 12)
|
||||
goto invalid_tile;
|
||||
|
||||
if (map.data[0] == 0xff && map.data[1] == J2K_MARKER_SOT) {
|
||||
if (map.data[0] == GST_J2K_MARKER && map.data[1] == GST_J2K_MARKER_SOT) {
|
||||
guint Psot, nPsot;
|
||||
|
||||
if (end[0] == 0xff && end[1] == J2K_MARKER_EOC)
|
||||
if (end[0] == GST_J2K_MARKER && end[1] == GST_J2K_MARKER_EOC)
|
||||
nPsot = avail - 2;
|
||||
else
|
||||
nPsot = avail;
|
||||
|
@ -391,9 +382,9 @@ gst_rtp_j2k_depay_flush_frame (GstRTPBaseDepayload * depayload)
|
|||
* marker */
|
||||
gst_adapter_copy (rtpj2kdepay->f_adapter, end, avail - 2, 2);
|
||||
|
||||
if (end[0] != 0xff && end[1] != 0xd9) {
|
||||
end[0] = 0xff;
|
||||
end[1] = 0xd9;
|
||||
if (end[0] != GST_J2K_MARKER && end[1] != GST_J2K_MARKER_EOC) {
|
||||
end[0] = GST_J2K_MARKER;
|
||||
end[1] = GST_J2K_MARKER_EOC;
|
||||
|
||||
GST_DEBUG_OBJECT (rtpj2kdepay, "no EOC marker, adding one");
|
||||
|
||||
|
@ -444,7 +435,7 @@ gst_rtp_j2k_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
|||
payload_len = gst_rtp_buffer_get_payload_len (rtp);
|
||||
|
||||
/* we need at least a header */
|
||||
if (payload_len < 8)
|
||||
if (payload_len < GST_RTP_J2K_HEADER_SIZE)
|
||||
goto empty_packet;
|
||||
|
||||
rtptime = gst_rtp_buffer_get_timestamp (rtp);
|
||||
|
@ -475,7 +466,7 @@ gst_rtp_j2k_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
|||
|
||||
tile = (payload[2] << 8) | payload[3];
|
||||
frag_offset = (payload[5] << 16) | (payload[6] << 8) | payload[7];
|
||||
j2klen = payload_len - 8;
|
||||
j2klen = payload_len - GST_RTP_J2K_HEADER_SIZE;
|
||||
|
||||
GST_DEBUG_OBJECT (rtpj2kdepay, "MHF %u, tile %u, frag %u, expected %u", MHF,
|
||||
tile, frag_offset, rtpj2kdepay->next_frag);
|
||||
|
@ -492,19 +483,19 @@ gst_rtp_j2k_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
|||
}
|
||||
|
||||
/* check for sync code */
|
||||
if (j2klen > 2 && payload[8] == 0xff) {
|
||||
guint marker = payload[9];
|
||||
if (j2klen > 2 && payload[GST_RTP_J2K_HEADER_SIZE] == GST_J2K_MARKER) {
|
||||
guint marker = payload[GST_RTP_J2K_HEADER_SIZE + 1];
|
||||
|
||||
/* packets must start with SOC, SOT or SOP */
|
||||
switch (marker) {
|
||||
case J2K_MARKER_SOC:
|
||||
case GST_J2K_MARKER_SOC:
|
||||
GST_DEBUG_OBJECT (rtpj2kdepay, "found SOC packet");
|
||||
/* flush the previous frame, should have happened when the timestamp
|
||||
* changed above. */
|
||||
gst_rtp_j2k_depay_flush_frame (depayload);
|
||||
rtpj2kdepay->have_sync = TRUE;
|
||||
break;
|
||||
case J2K_MARKER_SOT:
|
||||
case GST_J2K_MARKER_SOT:
|
||||
/* flush the previous tile */
|
||||
gst_rtp_j2k_depay_flush_tile (depayload);
|
||||
GST_DEBUG_OBJECT (rtpj2kdepay, "found SOT packet");
|
||||
|
@ -512,7 +503,7 @@ gst_rtp_j2k_depay_process (GstRTPBaseDepayload * depayload, GstRTPBuffer * rtp)
|
|||
/* we sync on the tile now */
|
||||
rtpj2kdepay->last_tile = tile;
|
||||
break;
|
||||
case J2K_MARKER_SOP:
|
||||
case GST_J2K_MARKER_SOP:
|
||||
GST_DEBUG_OBJECT (rtpj2kdepay, "found SOP packet");
|
||||
/* flush the previous PU */
|
||||
gst_rtp_j2k_depay_flush_pu (depayload);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <gst/rtp/gstrtpbasedepayload.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_RTP_J2K_DEPAY \
|
||||
(gst_rtp_j2k_depay_get_type())
|
||||
#define GST_RTP_J2K_DEPAY(obj) \
|
||||
|
@ -36,7 +35,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_J2K_DEPAY))
|
||||
#define GST_IS_RTP_J2K_DEPAY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_J2K_DEPAY))
|
||||
|
||||
typedef struct _GstRtpJ2KDepay GstRtpJ2KDepay;
|
||||
typedef struct _GstRtpJ2KDepayClass GstRtpJ2KDepayClass;
|
||||
|
||||
|
@ -71,5 +69,4 @@ GType gst_rtp_j2k_depay_get_type (void);
|
|||
gboolean gst_rtp_j2k_depay_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_RTP_J2K_DEPAY_H__ */
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
#include <string.h>
|
||||
#include <gst/rtp/gstrtpbuffer.h>
|
||||
#include <gst/video/video.h>
|
||||
|
||||
#include "gstrtpj2kcommon.h"
|
||||
#include "gstrtpj2kpay.h"
|
||||
#include "gstrtputils.h"
|
||||
|
||||
|
@ -65,25 +65,6 @@ GST_STATIC_PAD_TEMPLATE ("src",
|
|||
GST_DEBUG_CATEGORY_STATIC (rtpj2kpay_debug);
|
||||
#define GST_CAT_DEFAULT (rtpj2kpay_debug)
|
||||
|
||||
/*
|
||||
* RtpJ2KMarker:
|
||||
* @J2K_MARKER: Prefix for JPEG 2000 marker
|
||||
* @J2K_MARKER_SOC: Start of Codestream
|
||||
* @J2K_MARKER_SOT: Start of tile
|
||||
* @J2K_MARKER_EOC: End of Codestream
|
||||
*
|
||||
* Identifers for markers in JPEG 2000 codestreams
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
J2K_MARKER = 0xFF,
|
||||
J2K_MARKER_SOC = 0x4F,
|
||||
J2K_MARKER_SOT = 0x90,
|
||||
J2K_MARKER_SOP = 0x91,
|
||||
J2K_MARKER_EPH = 0x92,
|
||||
J2K_MARKER_SOD = 0x93,
|
||||
J2K_MARKER_EOC = 0xD9
|
||||
} RtpJ2KMarker;
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -102,8 +83,6 @@ typedef struct
|
|||
guint offset:24;
|
||||
} RtpJ2KHeader;
|
||||
|
||||
#define HEADER_SIZE 8
|
||||
|
||||
static void gst_rtp_j2k_pay_set_property (GObject * object, guint prop_id,
|
||||
const GValue * value, GParamSpec * pspec);
|
||||
static void gst_rtp_j2k_pay_get_property (GObject * object, guint prop_id,
|
||||
|
@ -186,16 +165,17 @@ gst_rtp_j2k_pay_header_size (const guint8 * data, guint offset)
|
|||
return data[offset] << 8 | data[offset + 1];
|
||||
}
|
||||
|
||||
static RtpJ2KMarker
|
||||
|
||||
static GstRtpJ2KMarker
|
||||
gst_rtp_j2k_pay_scan_marker (const guint8 * data, guint size, guint * offset)
|
||||
{
|
||||
while ((data[(*offset)++] != J2K_MARKER) && ((*offset) < size));
|
||||
while ((data[(*offset)++] != GST_J2K_MARKER) && ((*offset) < size));
|
||||
|
||||
if (G_UNLIKELY ((*offset) >= size)) {
|
||||
return J2K_MARKER_EOC;
|
||||
return GST_J2K_MARKER_EOC;
|
||||
} else {
|
||||
guint8 marker = data[(*offset)++];
|
||||
return marker;
|
||||
return (GstRtpJ2KMarker) marker;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +193,7 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
guint offset, RtpJ2KState * state)
|
||||
{
|
||||
gboolean cut_sop = FALSE;
|
||||
RtpJ2KMarker marker;
|
||||
GstRtpJ2KMarker marker;
|
||||
|
||||
/* parse the j2k header for 'start of codestream' */
|
||||
GST_LOG_OBJECT (pay, "checking from offset %u", offset);
|
||||
|
@ -223,13 +203,13 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
if (state->bitstream) {
|
||||
/* parsing bitstream, only look for SOP */
|
||||
switch (marker) {
|
||||
case J2K_MARKER_SOP:
|
||||
case GST_J2K_MARKER_SOP:
|
||||
GST_LOG_OBJECT (pay, "found SOP at %u", offset);
|
||||
if (cut_sop)
|
||||
return offset - 2;
|
||||
cut_sop = TRUE;
|
||||
break;
|
||||
case J2K_MARKER_EPH:
|
||||
case GST_J2K_MARKER_EPH:
|
||||
/* just skip over EPH */
|
||||
GST_LOG_OBJECT (pay, "found EPH at %u", offset);
|
||||
break;
|
||||
|
@ -238,7 +218,7 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
GST_LOG_OBJECT (pay, "reached next SOT at %u", offset);
|
||||
state->bitstream = FALSE;
|
||||
state->force_packet = TRUE;
|
||||
if (marker == J2K_MARKER_EOC && state->next_sot + 2 <= size)
|
||||
if (marker == GST_J2K_MARKER_EOC && state->next_sot + 2 <= size)
|
||||
/* include EOC but never go past the max size */
|
||||
return state->next_sot + 2;
|
||||
else
|
||||
|
@ -248,11 +228,11 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
}
|
||||
} else {
|
||||
switch (marker) {
|
||||
case J2K_MARKER_SOC:
|
||||
case GST_J2K_MARKER_SOC:
|
||||
GST_LOG_OBJECT (pay, "found SOC at %u", offset);
|
||||
state->header.MHF = 1;
|
||||
break;
|
||||
case J2K_MARKER_SOT:
|
||||
case GST_J2K_MARKER_SOT:
|
||||
{
|
||||
guint len, Psot;
|
||||
|
||||
|
@ -293,7 +273,7 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
Psot, state->next_sot);
|
||||
break;
|
||||
}
|
||||
case J2K_MARKER_SOD:
|
||||
case GST_J2K_MARKER_SOD:
|
||||
GST_LOG_OBJECT (pay, "found SOD at %u", offset);
|
||||
/* can't have more tiles now */
|
||||
state->n_tiles = 0;
|
||||
|
@ -305,7 +285,7 @@ find_pu_end (GstRtpJ2KPay * pay, const guint8 * data, guint size,
|
|||
* spec recommends packing headers separately */
|
||||
state->force_packet = TRUE;
|
||||
break;
|
||||
case J2K_MARKER_EOC:
|
||||
case GST_J2K_MARKER_EOC:
|
||||
GST_LOG_OBJECT (pay, "found EOC at %u", offset);
|
||||
return offset;
|
||||
default:
|
||||
|
@ -361,7 +341,8 @@ gst_rtp_j2k_pay_handle_buffer (GstRTPBasePayload * basepayload,
|
|||
state.force_packet = FALSE;
|
||||
|
||||
/* get max packet length */
|
||||
max_size = gst_rtp_buffer_calc_payload_len (mtu - HEADER_SIZE, 0, 0);
|
||||
max_size =
|
||||
gst_rtp_buffer_calc_payload_len (mtu - GST_RTP_J2K_HEADER_SIZE, 0, 0);
|
||||
|
||||
list = gst_buffer_list_new_sized ((mtu / max_size) + 1);
|
||||
|
||||
|
@ -416,7 +397,8 @@ gst_rtp_j2k_pay_handle_buffer (GstRTPBasePayload * basepayload,
|
|||
|
||||
/* calculate the packet size */
|
||||
packet_size =
|
||||
gst_rtp_buffer_calc_packet_len (pu_size + HEADER_SIZE, 0, 0);
|
||||
gst_rtp_buffer_calc_packet_len (pu_size + GST_RTP_J2K_HEADER_SIZE, 0,
|
||||
0);
|
||||
|
||||
if (packet_size > mtu) {
|
||||
GST_DEBUG_OBJECT (pay, "needed packet size %u clamped to MTU %u",
|
||||
|
@ -429,10 +411,10 @@ gst_rtp_j2k_pay_handle_buffer (GstRTPBasePayload * basepayload,
|
|||
|
||||
/* get total payload size and data size */
|
||||
payload_size = gst_rtp_buffer_calc_payload_len (packet_size, 0, 0);
|
||||
data_size = payload_size - HEADER_SIZE;
|
||||
data_size = payload_size - GST_RTP_J2K_HEADER_SIZE;
|
||||
|
||||
/* make buffer for header */
|
||||
outbuf = gst_rtp_buffer_new_allocate (HEADER_SIZE, 0, 0);
|
||||
outbuf = gst_rtp_buffer_new_allocate (GST_RTP_J2K_HEADER_SIZE, 0, 0);
|
||||
|
||||
GST_BUFFER_PTS (outbuf) = timestamp;
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <gst/rtp/gstrtpbasepayload.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_RTP_J2K_PAY \
|
||||
(gst_rtp_j2k_pay_get_type())
|
||||
#define GST_RTP_J2K_PAY(obj) \
|
||||
|
@ -35,7 +34,6 @@ G_BEGIN_DECLS
|
|||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_RTP_J2K_PAY))
|
||||
#define GST_IS_RTP_J2K_PAY_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_RTP_J2K_PAY))
|
||||
|
||||
typedef struct _GstRtpJ2KPay GstRtpJ2KPay;
|
||||
typedef struct _GstRtpJ2KPayClass GstRtpJ2KPayClass;
|
||||
|
||||
|
@ -57,5 +55,4 @@ GType gst_rtp_j2k_pay_get_type (void);
|
|||
gboolean gst_rtp_j2k_pay_plugin_init (GstPlugin * plugin);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_RTP_J2K_PAY_H__ */
|
||||
|
|
Loading…
Reference in a new issue