Skip to content

Commit

Permalink
Adding h264 timestamp field to AVTP h264 video header and fixed typo
Browse files Browse the repository at this point in the history
For details see IEEE 1722-2016 8.5.3.1 h264_timestamp field
  • Loading branch information
daejungkim committed Mar 18, 2018
1 parent c34c8cc commit 254f4d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
26 changes: 18 additions & 8 deletions lib/avtp_pipeline/map_h264/openavb_map_h264.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ Complete license and copyright information can be found at

// Header sizes
#define AVTP_V0_HEADER_SIZE 12
#define MAP_HEADER_SIZE 12
#define MAP_HEADER_SIZE 16

#define TOTAL_HEADER_SIZE (AVTP_V0_HEADER_SIZE + MAP_HEADER_SIZE)

#define MAX_PAYLOAD_SIZE 1412
#define MAX_PAYLOAD_SIZE 1416

//////
// AVTP Version 0 Header
Expand All @@ -84,7 +84,7 @@ Complete license and copyright information can be found at
//////

// - 4 bytes avtp_timestamp
#define HIDX_AVTP_TIMESPAMP32 12
#define HIDX_AVTP_TIMESTAMP32 12

// - 1 bytes Format information = 0x02 RTP Video
#define HIDX_FORMAT8 16
Expand All @@ -109,6 +109,9 @@ Complete license and copyright information can be found at
// - 1 byte Reserved = binary 0x00
#define HIDX_RESV8 23

// - 4 bytes h264_timestamp
#define HIDX_H264_TIMESTAMP32 24

typedef struct {
/////////////
// Config data
Expand Down Expand Up @@ -261,7 +264,7 @@ tx_cb_ret_t openavbMapH264TxCB(media_q_t *pMediaQ, U8 *pData, U32 *dataLen)
return TX_CB_RET_PACKET_NOT_READY;
}

//pHdr[HIDX_AVTP_TIMESPAMP32] = 0x00; // Set later
//pHdr[HIDX_AVTP_TIMESTAMP32] = 0x00; // Set later
pHdr[HIDX_FORMAT8] = 0x02; // RTP Payload type
pHdr[HIDX_FORMAT_SUBTYPE8] = 0x01; // H.264 subtype
pHdr[HIDX_RESV16] = 0x0000; // Reserved
Expand Down Expand Up @@ -295,7 +298,7 @@ tx_cb_ret_t openavbMapH264TxCB(media_q_t *pMediaQ, U8 *pData, U32 *dataLen)
else pHdr[HIDX_AVTP_HIDE7_TU1] &= ~0x01; // Clear

// Set the timestamp.
*(U32 *)(&pHdr[HIDX_AVTP_TIMESPAMP32]) = htonl(openavbAvtpTimeGetAvtpTimestamp(pMediaQItem->pAvtpTime));
*(U32 *)(&pHdr[HIDX_AVTP_TIMESTAMP32]) = htonl(openavbAvtpTimeGetAvtpTimestamp(pMediaQItem->pAvtpTime));

if (((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->lastPacket) {
pHdr[HIDX_M31_M21_M11_M01_EVT2_RESV2] = 0x10;;
Expand All @@ -304,7 +307,11 @@ tx_cb_ret_t openavbMapH264TxCB(media_q_t *pMediaQ, U8 *pData, U32 *dataLen)
pHdr[HIDX_M31_M21_M11_M01_EVT2_RESV2] = 0x00;
}

// Copy the JPEG fragment into the outgoing avtp packet.
// Set h264_timestamp
*(U32 *)(&pHdr[HIDX_H264_TIMESTAMP32]) =
htonl(((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->timestamp);

// Copy the h264 rtp payload into the outgoing avtp packet.
memcpy(pPayload, pMediaQItem->pPubData, pMediaQItem->dataLen);

*(U16 *)(&pHdr[HIDX_STREAM_DATA_LEN16]) = htons(pMediaQItem->dataLen);
Expand Down Expand Up @@ -347,7 +354,7 @@ bool openavbMapH264RxCB(media_q_t *pMediaQ, U8 *pData, U32 dataLen)
U8 *pPayload = pData + TOTAL_HEADER_SIZE;


//pHdr[HIDX_AVTP_TIMESPAMP32]
//pHdr[HIDX_AVTP_TIMESTAMP32]
//pHdr[HIDX_FORMAT8]
//pHdr[HIDX_FORMAT_SUBTYPE8]
//pHdr[HIDX_RESV16]
Expand All @@ -367,7 +374,7 @@ bool openavbMapH264RxCB(media_q_t *pMediaQ, U8 *pData, U32 dataLen)
media_q_item_t *pMediaQItem = openavbMediaQHeadLock(pMediaQ);
if (pMediaQItem) {
// Get the timestamp and place it in the media queue item.
U32 timestamp = ntohl(*(U32 *)(&pHdr[HIDX_AVTP_TIMESPAMP32]));
U32 timestamp = ntohl(*(U32 *)(&pHdr[HIDX_AVTP_TIMESTAMP32]));
openavbAvtpTimeSetToTimestamp(pMediaQItem->pAvtpTime, timestamp);

// Set timestamp valid and timestamp uncertain flags
Expand All @@ -379,6 +386,9 @@ bool openavbMapH264RxCB(media_q_t *pMediaQ, U8 *pData, U32 dataLen)
else
((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->lastPacket = FALSE;

((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->timestamp =
ntohl(*(U32 *)(&pHdr[HIDX_H264_TIMESTAMP32]));

if (pMediaQItem->itemSize >= payloadLen) {
memcpy(pMediaQItem->pPubData, pPayload, payloadLen);
pMediaQItem->dataLen = payloadLen;
Expand Down
2 changes: 2 additions & 0 deletions lib/avtp_pipeline/map_h264/openavb_map_h264_pub.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Complete license and copyright information can be found at
typedef struct {
// Last fragment of frame flag.
bool lastPacket; // For details see 1722a 9.4.3.1.1 M0 field
// The timestamp of h.264 NAL unit fragment.
U32 timestamp; // For details see 1722-2016 8.5.3.1 h264_timestamp field
} media_q_item_map_h264_pub_data_t;

#endif // OPENAVB_MAP_H264_PUB_H
8 changes: 8 additions & 0 deletions lib/avtp_pipeline/platform/Linux/gst_al/gst_al.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ gboolean gst_al_rtp_buffer_get_marker(GstAlBuf *buf);
* \param mark - a marker
*/
void gst_al_rtp_buffer_set_marker(GstAlBuf *buf, gboolean mark);
/**
* \brief - gets a RTP buffer timestamp
*
* \param buf - a RTP buffer
*
* \return - a RTP buffer timestamp
*/
guint32 gst_al_rtp_buffer_get_timestamp(GstAlBuf *buf);
/**
* \brief - set a RTP buffer params
*
Expand Down
5 changes: 5 additions & 0 deletions lib/avtp_pipeline/platform/Linux/gst_al/gst_al_10.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ void gst_al_rtp_buffer_set_marker(GstAlBuf *buf, gboolean mark)
gst_rtp_buffer_set_marker(&buf->m_rtpbuf, mark);
}

guint32 gst_al_rtp_buffer_get_timestamp(GstAlBuf *buf)
{
return gst_rtp_buffer_get_timestamp(&buf->m_rtpbuf);
}

void gst_al_rtp_buffer_set_params(GstAlBuf *buf, gint ssrc,
gint payload_type, gint version,
gint sequence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,8 @@ bool openavbIntfH264RtpGstTxCB(media_q_t *pMediaQ)
{
((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->lastPacket = FALSE;
}
((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->timestamp =
gst_al_rtp_buffer_get_timestamp(txBuf);
openavbAvtpTimeSetToWallTime(pMediaQItem->pAvtpTime);
openavbMediaQHeadPush(pMediaQ);

Expand Down Expand Up @@ -545,7 +547,8 @@ bool openavbIntfH264RtpGstRxCB(media_q_t *pMediaQ)
}
memcpy(GST_AL_BUF_DATA(rxBuf), pMediaQItem->pPubData, pMediaQItem->dataLen);

GST_AL_BUFFER_TIMESTAMP(rxBuf) = GST_CLOCK_TIME_NONE;
//GST_AL_BUFFER_TIMESTAMP(rxBuf) = GST_CLOCK_TIME_NONE;
GST_AL_BUFFER_TIMESTAMP(rxBuf) = ((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->timestamp;
GST_AL_BUFFER_DURATION(rxBuf) = GST_CLOCK_TIME_NONE;
if ( ((media_q_item_map_h264_pub_data_t *)pMediaQItem->pPubMapData)->lastPacket )
{
Expand Down

0 comments on commit 254f4d8

Please sign in to comment.