style fixes

This commit is contained in:
Roman Arutyunyan 2013-11-12 17:38:47 +04:00
parent c18fd3aad4
commit 85d34da0d4

View file

@ -6,35 +6,20 @@
#include <ngx_rtmp_codec_module.h> #include <ngx_rtmp_codec_module.h>
/* tie resolution */
#define NGX_RTMP_MP4_TIMESCALE 1000
/* normal forward playback as defined by spec */
#define NGX_RTMP_MP4_PREFERRED_RATE 0x00010000
/* full volume as defined by spec */
#define NGX_RTMP_MP4_PREFERRED_VOLUME 0x0100
static u_char compressor_name[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
/* /*
static ngx_int_t static ngx_int_t
ngx_rtmp_mp4_field_64(ngx_buf_t *b, uint64_t n) ngx_rtmp_mp4_field_64(ngx_buf_t *b, uint64_t n)
{ {
u_char bytes[8]; u_char bytes[8];
bytes[0] = ((uint64_t)n >> 56) & 0xFF; bytes[0] = ((uint64_t) n >> 56) & 0xFF;
bytes[1] = ((uint64_t)n >> 48) & 0xFF; bytes[1] = ((uint64_t) n >> 48) & 0xFF;
bytes[2] = ((uint64_t)n >> 40) & 0xFF; bytes[2] = ((uint64_t) n >> 40) & 0xFF;
bytes[3] = ((uint64_t)n >> 32) & 0xFF; bytes[3] = ((uint64_t) n >> 32) & 0xFF;
bytes[4] = ((uint64_t)n >> 24) & 0xFF; bytes[4] = ((uint64_t) n >> 24) & 0xFF;
bytes[5] = ((uint64_t)n >> 16) & 0xFF; bytes[5] = ((uint64_t) n >> 16) & 0xFF;
bytes[6] = ((uint64_t)n >> 8) & 0xFF; bytes[6] = ((uint64_t) n >> 8) & 0xFF;
bytes[7] = (uint64_t)n & 0xFF; bytes[7] = (uint64_t) n & 0xFF;
if (b->last + sizeof(bytes) > b->end) { if (b->last + sizeof(bytes) > b->end) {
return NGX_ERROR; return NGX_ERROR;
@ -51,10 +36,10 @@ ngx_rtmp_mp4_field_32(ngx_buf_t *b, uint32_t n)
{ {
u_char bytes[4]; u_char bytes[4];
bytes[0] = ((uint32_t)n >> 24) & 0xFF; bytes[0] = ((uint32_t) n >> 24) & 0xFF;
bytes[1] = ((uint32_t)n >> 16) & 0xFF; bytes[1] = ((uint32_t) n >> 16) & 0xFF;
bytes[2] = ((uint32_t)n >> 8) & 0xFF; bytes[2] = ((uint32_t) n >> 8) & 0xFF;
bytes[3] = (uint32_t)n & 0xFF; bytes[3] = (uint32_t) n & 0xFF;
if (b->last + sizeof(bytes) > b->end) { if (b->last + sizeof(bytes) > b->end) {
return NGX_ERROR; return NGX_ERROR;
@ -71,9 +56,9 @@ ngx_rtmp_mp4_field_24(ngx_buf_t *b, uint32_t n)
{ {
u_char bytes[3]; u_char bytes[3];
bytes[0] = ((uint32_t)n >> 16) & 0xFF; bytes[0] = ((uint32_t) n >> 16) & 0xFF;
bytes[1] = ((uint32_t)n >> 8) & 0xFF; bytes[1] = ((uint32_t) n >> 8) & 0xFF;
bytes[2] = (uint32_t)n & 0xFF; bytes[2] = (uint32_t) n & 0xFF;
if (b->last + sizeof(bytes) > b->end) { if (b->last + sizeof(bytes) > b->end) {
return NGX_ERROR; return NGX_ERROR;
@ -90,8 +75,8 @@ ngx_rtmp_mp4_field_16(ngx_buf_t *b, uint32_t n)
{ {
u_char bytes[2]; u_char bytes[2];
bytes[0] = ((uint32_t)n >> 8) & 0xFF; bytes[0] = ((uint32_t) n >> 8) & 0xFF;
bytes[1] = (uint32_t)n & 0xFF; bytes[1] = (uint32_t) n & 0xFF;
if (b->last + sizeof(bytes) > b->end) { if (b->last + sizeof(bytes) > b->end) {
return NGX_ERROR; return NGX_ERROR;
@ -121,15 +106,9 @@ ngx_rtmp_mp4_field_8(ngx_buf_t *b, unsigned int n)
static ngx_int_t static ngx_int_t
ngx_rtmp_mp4_put_descr(ngx_buf_t *b, int tag, unsigned int size) { ngx_rtmp_mp4_put_descr(ngx_buf_t *b, int tag, unsigned int size)
//int i = 3; {
/* initially stolen from ffmpeg, but most of it isnt necessary */
ngx_rtmp_mp4_field_8(b, tag); ngx_rtmp_mp4_field_8(b, tag);
//for (; i > 0; i--) {
// ngx_rtmp_mp4_field_8(b, (size >> (7 * i)) | 0x80);
//}
ngx_rtmp_mp4_field_8(b, size & 0x7F); ngx_rtmp_mp4_field_8(b, size & 0x7F);
return NGX_OK; return NGX_OK;
@ -144,7 +123,7 @@ ngx_rtmp_mp4_update_box_size(ngx_buf_t *b, u_char *pos)
curpos = b->last; curpos = b->last;
b->last = pos; b->last = pos;
ngx_rtmp_mp4_field_32(b, (curpos-pos)); ngx_rtmp_mp4_field_32(b, (uint32_t) (curpos - pos));
b->last = curpos; b->last = curpos;
@ -152,14 +131,18 @@ ngx_rtmp_mp4_update_box_size(ngx_buf_t *b, u_char *pos)
} }
/* transformation matrix
|a b u|
|c d v|
|tx ty w| */
static ngx_int_t static ngx_int_t
ngx_rtmp_mp4_write_matrix(ngx_buf_t *buf, int16_t a, int16_t b, int16_t c, ngx_rtmp_mp4_write_matrix(ngx_buf_t *buf, int16_t a, int16_t b, int16_t c,
int16_t d, int16_t tx, int16_t ty) int16_t d, int16_t tx, int16_t ty)
{ {
/*
* transformation matrix
* |a b u|
* |c d v|
* |tx ty w|
*/
ngx_rtmp_mp4_field_32(buf, a << 16); /* 16.16 format */ ngx_rtmp_mp4_field_32(buf, a << 16); /* 16.16 format */
ngx_rtmp_mp4_field_32(buf, b << 16); /* 16.16 format */ ngx_rtmp_mp4_field_32(buf, b << 16); /* 16.16 format */
ngx_rtmp_mp4_field_32(buf, 0); /* u in 2.30 format */ ngx_rtmp_mp4_field_32(buf, 0); /* u in 2.30 format */
@ -234,10 +217,10 @@ ngx_rtmp_mp4_write_mvhd(ngx_buf_t *b, ngx_rtmp_mp4_metadata_t *metadata)
ngx_rtmp_mp4_field_32(b, 0); /* version */ ngx_rtmp_mp4_field_32(b, 0); /* version */
ngx_rtmp_mp4_field_32(b, 0x00000000); /* creation time */ ngx_rtmp_mp4_field_32(b, 0x00000000); /* creation time */
ngx_rtmp_mp4_field_32(b, 0); /* modification time */ ngx_rtmp_mp4_field_32(b, 0); /* modification time */
ngx_rtmp_mp4_field_32(b, NGX_RTMP_MP4_TIMESCALE); /* timescale */ ngx_rtmp_mp4_field_32(b, 1000); /* timescale */
ngx_rtmp_mp4_field_32(b, 0); /* duration */ ngx_rtmp_mp4_field_32(b, 0); /* duration */
ngx_rtmp_mp4_field_32(b, NGX_RTMP_MP4_PREFERRED_RATE); /* playback rate */ ngx_rtmp_mp4_field_32(b, 0x00010000); /* playback rate */
ngx_rtmp_mp4_field_16(b, NGX_RTMP_MP4_PREFERRED_VOLUME); /* volume rate */ ngx_rtmp_mp4_field_16(b, 0x0100); /* volume rate */
ngx_rtmp_mp4_field_16(b, 0); /* reserved */ ngx_rtmp_mp4_field_16(b, 0); /* reserved */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ ngx_rtmp_mp4_field_32(b, 0); /* reserved */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ ngx_rtmp_mp4_field_32(b, 0); /* reserved */
@ -324,7 +307,7 @@ ngx_rtmp_mp4_write_mdhd(ngx_buf_t *b)
ngx_rtmp_mp4_field_32(b, 0); ngx_rtmp_mp4_field_32(b, 0);
/* time scale*/ /* time scale*/
ngx_rtmp_mp4_field_32(b, NGX_RTMP_MP4_TIMESCALE); ngx_rtmp_mp4_field_32(b, 1000);
/* duration */ /* duration */
ngx_rtmp_mp4_field_32(b, 0); ngx_rtmp_mp4_field_32(b, 0);
@ -466,8 +449,8 @@ ngx_rtmp_mp4_write_avcc(ngx_rtmp_session_t *s, ngx_buf_t *b,
ngx_rtmp_mp4_metadata_t *metadata) ngx_rtmp_mp4_metadata_t *metadata)
{ {
u_char *pos, *p; u_char *pos, *p;
ngx_rtmp_codec_ctx_t *codec_ctx;
ngx_chain_t *in; ngx_chain_t *in;
ngx_rtmp_codec_ctx_t *codec_ctx;
codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module); codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module);
@ -518,37 +501,54 @@ ngx_rtmp_mp4_write_video(ngx_rtmp_session_t *s, ngx_buf_t *b,
/* box size placeholder */ /* box size placeholder */
ngx_rtmp_mp4_field_32(b, 0); ngx_rtmp_mp4_field_32(b, 0);
b->last = ngx_cpymem(b->last, "avc1", sizeof("avc1")-1); b->last = ngx_cpymem(b->last, "avc1", sizeof("avc1") - 1);
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ /* reserved */
ngx_rtmp_mp4_field_16(b, 0); /* reserved */ ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_16(b, 1); /* data reference index */ ngx_rtmp_mp4_field_16(b, 0);
ngx_rtmp_mp4_field_16(b, 0); /* codec stream version */
ngx_rtmp_mp4_field_16(b, 0); /* codec stream revision (=0) */ /* data reference index */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ ngx_rtmp_mp4_field_16(b, 1);
ngx_rtmp_mp4_field_32(b, 0); /* reserved */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ /* codec stream version & revision */
ngx_rtmp_mp4_field_16(b, 0);
ngx_rtmp_mp4_field_16(b, 0);
/* reserved */
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
/* width & height */
ngx_rtmp_mp4_field_16(b, metadata->width); ngx_rtmp_mp4_field_16(b, metadata->width);
ngx_rtmp_mp4_field_16(b, metadata->height); ngx_rtmp_mp4_field_16(b, metadata->height);
ngx_rtmp_mp4_field_32(b, 0x00480000); /* Horizontal resolution 72dpi */
ngx_rtmp_mp4_field_32(b, 0x00480000); /* Vertical resolution 72dpi */
ngx_rtmp_mp4_field_32(b, 0); /* Data size (= 0) */
ngx_rtmp_mp4_field_16(b, 1); /* Frame count (= 1) */
ngx_rtmp_mp4_field_8(b, 0); /* compressor name len */
b->last = ngx_cpymem(b->last, compressor_name, sizeof(compressor_name)+1); /* horizontal & vertical resolutions 72 dpi */
ngx_rtmp_mp4_field_32(b, 0x00480000);
ngx_rtmp_mp4_field_32(b, 0x00480000);
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ /* data size */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0); /* reserved */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ /* frame count */
ngx_rtmp_mp4_field_32(b, 0); /* reserved */ ngx_rtmp_mp4_field_16(b, 1);
ngx_rtmp_mp4_field_16(b, 0x18); /* reserved */
ngx_rtmp_mp4_field_16(b, 0xffff); /* reserved */ /* compressor name */
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
/* reserved */
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_32(b, 0);
ngx_rtmp_mp4_field_16(b, 0x18);
ngx_rtmp_mp4_field_16(b, 0xffff);
ngx_rtmp_mp4_write_avcc(s, b, metadata); ngx_rtmp_mp4_write_avcc(s, b, metadata);
ngx_rtmp_mp4_update_box_size(b, pos); ngx_rtmp_mp4_update_box_size(b, pos);
return NGX_OK; return NGX_OK;
@ -559,12 +559,11 @@ static ngx_int_t
ngx_rtmp_mp4_write_esds(ngx_rtmp_session_t *s, ngx_buf_t *b, ngx_rtmp_mp4_write_esds(ngx_rtmp_session_t *s, ngx_buf_t *b,
ngx_rtmp_mp4_metadata_t *metadata) ngx_rtmp_mp4_metadata_t *metadata)
{ {
u_char *pos;
ngx_rtmp_codec_ctx_t *codec_ctx;
ngx_chain_t *aac;
int decoder_info; int decoder_info;
int aac_header_offset; int aac_header_offset;
u_char *pos;
ngx_chain_t *aac;
ngx_rtmp_codec_ctx_t *codec_ctx;
codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module); codec_ctx = ngx_rtmp_get_module_ctx(s, ngx_rtmp_codec_module);
@ -1125,7 +1124,7 @@ ngx_rtmp_mp4_write_sidx(ngx_buf_t *b, ngx_uint_t reference_size,
ngx_rtmp_mp4_field_32(b, 1); ngx_rtmp_mp4_field_32(b, 1);
/* timescale */ /* timescale */
ngx_rtmp_mp4_field_32(b, NGX_RTMP_MP4_TIMESCALE); ngx_rtmp_mp4_field_32(b, 1000);
/* earliest presentation time */ /* earliest presentation time */
ngx_rtmp_mp4_field_32(b, earliest_pres_time); ngx_rtmp_mp4_field_32(b, earliest_pres_time);
@ -1186,7 +1185,7 @@ ngx_rtmp_mp4_write_mdat(ngx_buf_t *b, ngx_uint_t size)
{ {
ngx_rtmp_mp4_field_32(b, size); ngx_rtmp_mp4_field_32(b, size);
b->last = ngx_cpymem(b->last, "mdat", sizeof("mdat")-1); b->last = ngx_cpymem(b->last, "mdat", sizeof("mdat") - 1);
return NGX_OK; return NGX_OK;
} }