summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/baresip.h71
-rw-r--r--modules/avcodec/avcodec.c3
-rw-r--r--modules/avcodec/avcodec.h6
-rw-r--r--modules/avcodec/decode.c4
-rw-r--r--modules/avcodec/encode.c3
-rw-r--r--modules/avcodec/h26x.h61
-rw-r--r--modules/avcodec/module.mk2
-rw-r--r--src/h264.c (renamed from modules/avcodec/h264.c)25
-rw-r--r--src/srcs.mk1
9 files changed, 88 insertions, 88 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 67fef23..b607166 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -923,6 +923,77 @@ int sip_req_send(struct ua *ua, const char *method, const char *uri,
/*
+ * H.264
+ */
+
+/** NAL unit types (RFC 3984, Table 1) */
+enum {
+ H264_NAL_UNKNOWN = 0,
+ /* 1-23 NAL unit Single NAL unit packet per H.264 */
+ H264_NAL_SLICE = 1,
+ H264_NAL_DPA = 2,
+ H264_NAL_DPB = 3,
+ H264_NAL_DPC = 4,
+ H264_NAL_IDR_SLICE = 5,
+ H264_NAL_SEI = 6,
+ H264_NAL_SPS = 7,
+ H264_NAL_PPS = 8,
+ H264_NAL_AUD = 9,
+ H264_NAL_END_SEQUENCE = 10,
+ H264_NAL_END_STREAM = 11,
+ H264_NAL_FILLER_DATA = 12,
+ H264_NAL_SPS_EXT = 13,
+ H264_NAL_AUX_SLICE = 19,
+
+ H264_NAL_STAP_A = 24, /**< Single-time aggregation packet */
+ H264_NAL_STAP_B = 25, /**< Single-time aggregation packet */
+ H264_NAL_MTAP16 = 26, /**< Multi-time aggregation packet */
+ H264_NAL_MTAP24 = 27, /**< Multi-time aggregation packet */
+ H264_NAL_FU_A = 28, /**< Fragmentation unit */
+ H264_NAL_FU_B = 29, /**< Fragmentation unit */
+};
+
+/**
+ * H.264 Header defined in RFC 3984
+ *
+ * <pre>
+ +---------------+
+ |0|1|2|3|4|5|6|7|
+ +-+-+-+-+-+-+-+-+
+ |F|NRI| Type |
+ +---------------+
+ * </pre>
+ */
+struct h264_hdr {
+ unsigned f:1; /**< 1 bit - Forbidden zero bit (must be 0) */
+ unsigned nri:2; /**< 2 bits - nal_ref_idc */
+ unsigned type:5; /**< 5 bits - nal_unit_type */
+};
+
+int h264_hdr_encode(const struct h264_hdr *hdr, struct mbuf *mb);
+int h264_hdr_decode(struct h264_hdr *hdr, struct mbuf *mb);
+
+/** Fragmentation Unit header */
+struct h264_fu {
+ unsigned s:1; /**< Start bit */
+ unsigned e:1; /**< End bit */
+ unsigned r:1; /**< The Reserved bit MUST be equal to 0 */
+ unsigned type:5; /**< The NAL unit payload type */
+};
+
+int h264_fu_hdr_encode(const struct h264_fu *fu, struct mbuf *mb);
+int h264_fu_hdr_decode(struct h264_fu *fu, struct mbuf *mb);
+
+const uint8_t *h264_find_startcode(const uint8_t *p, const uint8_t *end);
+
+int h264_packetize(const uint8_t *buf, size_t len, size_t pktsize,
+ videnc_packet_h *pkth, void *arg);
+int h264_nal_send(bool first, bool last,
+ bool marker, uint32_t ihdr, const uint8_t *buf,
+ size_t size, size_t maxsz,
+ videnc_packet_h *pkth, void *arg);
+
+/*
* Modules
*/
diff --git a/modules/avcodec/avcodec.c b/modules/avcodec/avcodec.c
index dfcd38d..3df9ba7 100644
--- a/modules/avcodec/avcodec.c
+++ b/modules/avcodec/avcodec.c
@@ -14,6 +14,9 @@
#include "avcodec.h"
+const uint8_t h264_level_idc = 0x0c;
+
+
int avcodec_resolve_codecid(const char *s)
{
if (0 == str_casecmp(s, "H263"))
diff --git a/modules/avcodec/avcodec.h b/modules/avcodec/avcodec.h
index 890df5f..f3f0398 100644
--- a/modules/avcodec/avcodec.h
+++ b/modules/avcodec/avcodec.h
@@ -55,13 +55,7 @@ int decode_h263_test(struct viddec_state *st, struct vidframe *frame,
int decode_sdpparam_h264(struct videnc_state *st, const struct pl *name,
const struct pl *val);
-int h264_packetize(struct mbuf *mb, size_t pktsize,
- videnc_packet_h *pkth, void *arg);
int h264_decode(struct viddec_state *st, struct mbuf *src);
-int h264_nal_send(bool first, bool last,
- bool marker, uint32_t ihdr, const uint8_t *buf,
- size_t size, size_t maxsz,
- videnc_packet_h *pkth, void *arg);
int avcodec_resolve_codecid(const char *s);
diff --git a/modules/avcodec/decode.c b/modules/avcodec/decode.c
index 06d43b0..5fb6b6f 100644
--- a/modules/avcodec/decode.c
+++ b/modules/avcodec/decode.c
@@ -219,9 +219,9 @@ int h264_decode(struct viddec_state *st, struct mbuf *src)
err = h264_hdr_encode(&h264_hdr, st->mb);
}
else if (H264_NAL_FU_A == h264_hdr.type) {
- struct fu fu;
+ struct h264_fu fu;
- err = fu_hdr_decode(&fu, src);
+ err = h264_fu_hdr_decode(&fu, src);
if (err)
return err;
h264_hdr.type = fu.type;
diff --git a/modules/avcodec/encode.c b/modules/avcodec/encode.c
index 6e51d63..69e2bbf 100644
--- a/modules/avcodec/encode.c
+++ b/modules/avcodec/encode.c
@@ -632,7 +632,8 @@ int encode(struct videnc_state *st, bool update, const struct vidframe *frame)
break;
case AV_CODEC_ID_H264:
- err = h264_packetize(st->mb, st->encprm.pktsize,
+ err = h264_packetize(st->mb->buf, st->mb->end,
+ st->encprm.pktsize,
st->pkth, st->arg);
break;
diff --git a/modules/avcodec/h26x.h b/modules/avcodec/h26x.h
index 7a21696..faff489 100644
--- a/modules/avcodec/h26x.h
+++ b/modules/avcodec/h26x.h
@@ -101,65 +101,4 @@ void h263_hdr_copy_strm(struct h263_hdr *hdr, const struct h263_strm *s);
* H.264
*/
-
-/** NAL unit types (RFC 3984, Table 1) */
-enum {
- H264_NAL_UNKNOWN = 0,
- /* 1-23 NAL unit Single NAL unit packet per H.264 */
- H264_NAL_SLICE = 1,
- H264_NAL_DPA = 2,
- H264_NAL_DPB = 3,
- H264_NAL_DPC = 4,
- H264_NAL_IDR_SLICE = 5,
- H264_NAL_SEI = 6,
- H264_NAL_SPS = 7,
- H264_NAL_PPS = 8,
- H264_NAL_AUD = 9,
- H264_NAL_END_SEQUENCE = 10,
- H264_NAL_END_STREAM = 11,
- H264_NAL_FILLER_DATA = 12,
- H264_NAL_SPS_EXT = 13,
- H264_NAL_AUX_SLICE = 19,
-
- H264_NAL_STAP_A = 24, /**< Single-time aggregation packet */
- H264_NAL_STAP_B = 25, /**< Single-time aggregation packet */
- H264_NAL_MTAP16 = 26, /**< Multi-time aggregation packet */
- H264_NAL_MTAP24 = 27, /**< Multi-time aggregation packet */
- H264_NAL_FU_A = 28, /**< Fragmentation unit */
- H264_NAL_FU_B = 29, /**< Fragmentation unit */
-};
-
-/**
- * H.264 Header defined in RFC 3984
- *
- * <pre>
- +---------------+
- |0|1|2|3|4|5|6|7|
- +-+-+-+-+-+-+-+-+
- |F|NRI| Type |
- +---------------+
- * </pre>
- */
-struct h264_hdr {
- unsigned f:1; /**< 1 bit - Forbidden zero bit (must be 0) */
- unsigned nri:2; /**< 2 bits - nal_ref_idc */
- unsigned type:5; /**< 5 bits - nal_unit_type */
-};
-
-int h264_hdr_encode(const struct h264_hdr *hdr, struct mbuf *mb);
-int h264_hdr_decode(struct h264_hdr *hdr, struct mbuf *mb);
-
-/** Fragmentation Unit header */
-struct fu {
- unsigned s:1; /**< Start bit */
- unsigned e:1; /**< End bit */
- unsigned r:1; /**< The Reserved bit MUST be equal to 0 */
- unsigned type:5; /**< The NAL unit payload type */
-};
-
-int fu_hdr_encode(const struct fu *fu, struct mbuf *mb);
-int fu_hdr_decode(struct fu *fu, struct mbuf *mb);
-
-const uint8_t *h264_find_startcode(const uint8_t *p, const uint8_t *end);
-
int h264_decode_sprop_params(AVCodecContext *codec, struct pl *pl);
diff --git a/modules/avcodec/module.mk b/modules/avcodec/module.mk
index acff21b..1927a94 100644
--- a/modules/avcodec/module.mk
+++ b/modules/avcodec/module.mk
@@ -9,7 +9,7 @@ USE_X264 := $(shell [ -f $(SYSROOT)/include/x264.h ] || \
[ -f $(SYSROOT_ALT)/include/x264.h ] && echo "yes")
MOD := avcodec
-$(MOD)_SRCS += avcodec.c h263.c h264.c encode.c decode.c
+$(MOD)_SRCS += avcodec.c h263.c encode.c decode.c
$(MOD)_LFLAGS += -lavcodec -lavutil
CFLAGS += -DUSE_AVCODEC
ifneq ($(USE_X264),)
diff --git a/modules/avcodec/h264.c b/src/h264.c
index 4c2aa59..8da811d 100644
--- a/modules/avcodec/h264.c
+++ b/src/h264.c
@@ -1,21 +1,12 @@
/**
- * @file avcodec/h264.c H.264 video codec (RFC 3984)
+ * @file src/h264.c H.264 video codec packetization (RFC 3984)
*
- * Copyright (C) 2010 Creytiv.com
+ * Copyright (C) 2010 - 2015 Creytiv.com
*/
#include <string.h>
#include <re.h>
#include <rem.h>
#include <baresip.h>
-#include <libavcodec/avcodec.h>
-#ifdef USE_X264
-#include <x264.h>
-#endif
-#include "h26x.h"
-#include "avcodec.h"
-
-
-const uint8_t h264_level_idc = 0x0c;
int h264_hdr_encode(const struct h264_hdr *hdr, struct mbuf *mb)
@@ -45,14 +36,14 @@ int h264_hdr_decode(struct h264_hdr *hdr, struct mbuf *mb)
}
-int fu_hdr_encode(const struct fu *fu, struct mbuf *mb)
+int h264_fu_hdr_encode(const struct h264_fu *fu, struct mbuf *mb)
{
uint8_t v = fu->s<<7 | fu->s<<6 | fu->r<<5 | fu->type;
return mbuf_write_u8(mb, v);
}
-int fu_hdr_decode(struct fu *fu, struct mbuf *mb)
+int h264_fu_hdr_decode(struct h264_fu *fu, struct mbuf *mb)
{
uint8_t v;
@@ -159,15 +150,15 @@ int h264_nal_send(bool first, bool last,
}
-int h264_packetize(struct mbuf *mb, size_t pktsize,
+int h264_packetize(const uint8_t *buf, size_t len, size_t pktsize,
videnc_packet_h *pkth, void *arg)
{
- const uint8_t *start = mb->buf;
- const uint8_t *end = start + mb->end;
+ const uint8_t *start = buf;
+ const uint8_t *end = buf + len;
const uint8_t *r;
int err = 0;
- r = h264_find_startcode(mb->buf, end);
+ r = h264_find_startcode(start, end);
while (r < end) {
const uint8_t *r1;
diff --git a/src/srcs.mk b/src/srcs.mk
index d3aa765..3c042ec 100644
--- a/src/srcs.mk
+++ b/src/srcs.mk
@@ -34,6 +34,7 @@ SRCS += ui.c
ifneq ($(USE_VIDEO),)
SRCS += bfcp.c
+SRCS += h264.c
SRCS += mctrl.c
SRCS += video.c
SRCS += vidcodec.c