forked from aizvorski/h264bitstream
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ec943a
commit 1c1217e
Showing
1 changed file
with
28 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
/* | ||
/* | ||
* h264bitstream - a library for reading and writing H.264 video | ||
* Copyright (C) 2005-2007 Auroras Entertainment, LLC | ||
* Copyright (C) 2008-2011 Avail-TVN | ||
* | ||
* | ||
* Written by Alex Izvorski <[email protected]> and Alex Giladi <[email protected]> | ||
* | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 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 | ||
* Lesser General Public License for more details. | ||
* | ||
* | ||
* You should have received a copy of the GNU Lesser 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 | ||
|
@@ -39,7 +39,7 @@ h264_stream_t* h264_new() | |
h->nal = (nal_t*)calloc(1, sizeof(nal_t)); | ||
h->nal->nal_svc_ext = (nal_svc_ext_t*) calloc(1, sizeof(nal_svc_ext_t)); | ||
h->nal->prefix_nal_svc = (prefix_nal_svc_t*) calloc(1, sizeof(prefix_nal_svc_t)); | ||
|
||
// initialize tables | ||
for ( int i = 0; i < 32; i++ ) { h->sps_table[i] = (sps_t*)calloc(1, sizeof(sps_t)); } | ||
for ( int i = 0; i < 64; i++ ) | ||
|
@@ -100,7 +100,7 @@ void h264_free(h264_stream_t* h) | |
free(h->seis); | ||
} | ||
free(h->sh); | ||
|
||
if (h->sh_svc_ext != NULL) free(h->sh_svc_ext); | ||
|
||
if (h->slice_data != NULL) | ||
|
@@ -137,11 +137,11 @@ int find_nal_unit(uint8_t* buf, int size, int* nal_start, int* nal_end) | |
// find start | ||
*nal_start = 0; | ||
*nal_end = 0; | ||
|
||
i = 0; | ||
while ( //( next_bits( 24 ) != 0x000001 && next_bits( 32 ) != 0x00000001 ) | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) && | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0 || buf[i+3] != 0x01) | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) && | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0 || buf[i+3] != 0x01) | ||
) | ||
{ | ||
i++; // skip leading zero | ||
|
@@ -156,17 +156,17 @@ int find_nal_unit(uint8_t* buf, int size, int* nal_start, int* nal_end) | |
if (buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) { /* error, should never happen */ return 0; } | ||
i+= 3; | ||
*nal_start = i; | ||
|
||
while ( //( next_bits( 24 ) != 0x000000 && next_bits( 24 ) != 0x000001 ) | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0) && | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0) && | ||
(buf[i] != 0 || buf[i+1] != 0 || buf[i+2] != 0x01) | ||
) | ||
{ | ||
i++; | ||
// FIXME the next line fails when reading a nal that ends exactly at the end of the data | ||
if (i+3 >= size) { *nal_end = size; return -1; } // did not find nal end, stream ended first | ||
} | ||
|
||
*nal_end = i; | ||
return (*nal_end - *nal_start); | ||
} | ||
|
@@ -188,14 +188,14 @@ int find_nal_unit(uint8_t* buf, int size, int* nal_start, int* nal_end) | |
int rbsp_to_nal(const uint8_t* rbsp_buf, const int* rbsp_size, uint8_t* nal_buf, int* nal_size) | ||
{ | ||
int i; | ||
int j = 1; | ||
int j = 0; | ||
int count = 0; | ||
|
||
if (*nal_size > 0) { nal_buf[0] = 0x00; } // zero out first byte since we start writing from second byte | ||
// if (*nal_size > 0) { nal_buf[0] = 0x00; } // zero out first byte since we start writing from second byte | ||
|
||
for ( i = 0; i < *rbsp_size ; ) | ||
{ | ||
if ( j >= *nal_size ) | ||
if ( j >= *nal_size ) | ||
{ | ||
// error, not enough space | ||
return -1; | ||
|
@@ -228,7 +228,7 @@ int rbsp_to_nal(const uint8_t* rbsp_buf, const int* rbsp_size, uint8_t* nal_buf, | |
/** | ||
Convert NAL data (Annex B format) to RBSP data. | ||
The size of rbsp_buf must be the same as size of the nal_buf to guarantee the output will fit. | ||
If that is not true, output may be truncated and an error will be returned. | ||
If that is not true, output may be truncated and an error will be returned. | ||
Additionally, certain byte sequences in the input nal_buf are not allowed in the spec and also cause the conversion to fail and an error to be returned. | ||
@param[in] nal_buf the nal data | ||
@param[in,out] nal_size as input, pointer to the size of the nal data; as output, filled in with the actual size of the nal data | ||
|
@@ -243,11 +243,11 @@ int nal_to_rbsp(const uint8_t* nal_buf, int* nal_size, uint8_t* rbsp_buf, int* r | |
int i; | ||
int j = 0; | ||
int count = 0; | ||
|
||
for( i = 0; i < *nal_size; i++ ) | ||
{ | ||
{ | ||
// in NAL unit, 0x000000, 0x000001 or 0x000002 shall not occur at any byte-aligned position | ||
if( ( count == 2 ) && ( nal_buf[i] < 0x03) ) | ||
if( ( count == 2 ) && ( nal_buf[i] < 0x03) ) | ||
{ | ||
return -1; | ||
} | ||
|
@@ -270,7 +270,7 @@ int nal_to_rbsp(const uint8_t* nal_buf, int* nal_size, uint8_t* rbsp_buf, int* r | |
count = 0; | ||
} | ||
|
||
if ( j >= *rbsp_size ) | ||
if ( j >= *rbsp_size ) | ||
{ | ||
// error, not enough space | ||
return -1; | ||
|
@@ -322,13 +322,13 @@ int peek_nal_unit(h264_stream_t* h, uint8_t* buf, int size) | |
return -1; | ||
} | ||
} | ||
else | ||
else | ||
{ | ||
if ( nal->nal_unit_type == NAL_UNIT_TYPE_SEI || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_AUD || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_END_OF_SEQUENCE || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_END_OF_STREAM || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_FILLER ) | ||
if ( nal->nal_unit_type == NAL_UNIT_TYPE_SEI || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_AUD || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_END_OF_SEQUENCE || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_END_OF_STREAM || | ||
nal->nal_unit_type == NAL_UNIT_TYPE_FILLER ) | ||
{ | ||
return -1; | ||
} | ||
|