正在显示
3 个修改的文件
包含
368 行增加
和
187 行删除
| @@ -249,6 +249,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -249,6 +249,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 249 | #define ERROR_MP4_BOX_STRING 3073 | 249 | #define ERROR_MP4_BOX_STRING 3073 |
| 250 | #define ERROR_MP4_BOX_ILLEGAL_BRAND 3074 | 250 | #define ERROR_MP4_BOX_ILLEGAL_BRAND 3074 |
| 251 | #define ERROR_MP4_NOT_NON_SEEKABLE 3075 | 251 | #define ERROR_MP4_NOT_NON_SEEKABLE 3075 |
| 252 | +#define ERROR_MP4_ESDS_SL_Config 3076 | ||
| 252 | 253 | ||
| 253 | /////////////////////////////////////////////////////// | 254 | /////////////////////////////////////////////////////// |
| 254 | // HTTP/StreamCaster/KAFKA protocol error. | 255 | // HTTP/StreamCaster/KAFKA protocol error. |
| @@ -33,50 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -33,50 +33,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 33 | #include <string.h> | 33 | #include <string.h> |
| 34 | using namespace std; | 34 | using namespace std; |
| 35 | 35 | ||
| 36 | -#define SRS_MP4_BOX_UUID 0x75756964 // 'uuid' | ||
| 37 | -#define SRS_MP4_BOX_FTYP 0x66747970 // 'ftyp' | ||
| 38 | -#define SRS_MP4_BOX_MDAT 0x6d646174 // 'mdat' | ||
| 39 | -#define SRS_MP4_BOX_FREE 0x66726565 // 'free' | ||
| 40 | -#define SRS_MP4_BOX_SKIP 0x736b6970 // 'skip' | ||
| 41 | -#define SRS_MP4_BOX_MOOV 0x6d6f6f76 // 'moov' | ||
| 42 | -#define SRS_MP4_BOX_MVHD 0x6d766864 // 'mvhd' | ||
| 43 | -#define SRS_MP4_BOX_TRAK 0x7472616b // 'trak' | ||
| 44 | -#define SRS_MP4_BOX_TKHD 0x746b6864 // 'tkhd' | ||
| 45 | -#define SRS_MP4_BOX_EDTS 0x65647473 // 'edts' | ||
| 46 | -#define SRS_MP4_BOX_ELST 0x656c7374 // 'elst' | ||
| 47 | -#define SRS_MP4_BOX_MDIA 0x6d646961 // 'mdia' | ||
| 48 | -#define SRS_MP4_BOX_MDHD 0x6d646864 // 'mdhd' | ||
| 49 | -#define SRS_MP4_BOX_HDLR 0x68646c72 // 'hdlr' | ||
| 50 | -#define SRS_MP4_BOX_MINF 0x6d696e66 // 'minf' | ||
| 51 | -#define SRS_MP4_BOX_VMHD 0x766d6864 // 'vmhd' | ||
| 52 | -#define SRS_MP4_BOX_SMHD 0x736d6864 // 'smhd' | ||
| 53 | -#define SRS_MP4_BOX_DINF 0x64696e66 // 'dinf' | ||
| 54 | -#define SRS_MP4_BOX_URL 0x75726c20 // 'url ' | ||
| 55 | -#define SRS_MP4_BOX_URN 0x75726e20 // 'urn ' | ||
| 56 | -#define SRS_MP4_BOX_DREF 0x64726566 // 'dref' | ||
| 57 | -#define SRS_MP4_BOX_STBL 0x7374626c // 'stbl' | ||
| 58 | -#define SRS_MP4_BOX_STSD 0x73747364 // 'stsd' | ||
| 59 | -#define SRS_MP4_BOX_STTS 0x73747473 // 'stts' | ||
| 60 | -#define SRS_MP4_BOX_CTTS 0x63747473 // 'ctts' | ||
| 61 | -#define SRS_MP4_BOX_STSS 0x73747373 // 'stss' | ||
| 62 | -#define SRS_MP4_BOX_STSC 0x73747363 // 'stsc' | ||
| 63 | -#define SRS_MP4_BOX_STCO 0x7374636f // 'stco' | ||
| 64 | -#define SRS_MP4_BOX_CO64 0x636f3634 // 'co64' | ||
| 65 | -#define SRS_MP4_BOX_STSZ 0x7374737a // 'stsz' | ||
| 66 | -#define SRS_MP4_BOX_STZ2 0x73747a32 // 'stz2' | ||
| 67 | -#define SRS_MP4_BOX_AVC1 0x61766331 // 'avc1' | ||
| 68 | -#define SRS_MP4_BOX_AVCC 0x61766343 // 'avcC' | ||
| 69 | -#define SRS_MP4_BOX_MP4A 0x6d703461 // 'mp4a' | ||
| 70 | -#define SRS_MP4_BOX_ESDS 0x65736473 // 'esds' | ||
| 71 | - | ||
| 72 | -#define SRS_MP4_BRAND_ISOM 0x69736f6d // 'isom' | ||
| 73 | -#define SRS_MP4_BRAND_ISO2 0x69736f32 // 'iso2' | ||
| 74 | -#define SRS_MP4_BRAND_AVC1 0x61766331 // 'avc1' | ||
| 75 | -#define SRS_MP4_BRAND_MP41 0x6d703431 // 'mp41' | ||
| 76 | - | ||
| 77 | -#define SRS_MP4_HANDLER_VIDE 0x76696465 // 'vide' | ||
| 78 | -#define SRS_MP4_HANDLER_SOUN 0x736f756e // 'soun' | ||
| 79 | - | ||
| 80 | #define SRS_MP4_EOF_SIZE 0 | 36 | #define SRS_MP4_EOF_SIZE 0 |
| 81 | #define SRS_MP4_USE_LARGE_SIZE 1 | 37 | #define SRS_MP4_USE_LARGE_SIZE 1 |
| 82 | 38 | ||
| @@ -125,7 +81,7 @@ SrsMp4Box::SrsMp4Box() | @@ -125,7 +81,7 @@ SrsMp4Box::SrsMp4Box() | ||
| 125 | largesize = 0; | 81 | largesize = 0; |
| 126 | usertype = NULL; | 82 | usertype = NULL; |
| 127 | start_pos = 0; | 83 | start_pos = 0; |
| 128 | - type = 0; | 84 | + type = SrsMp4BoxTypeForbidden; |
| 129 | } | 85 | } |
| 130 | 86 | ||
| 131 | SrsMp4Box::~SrsMp4Box() | 87 | SrsMp4Box::~SrsMp4Box() |
| @@ -152,17 +108,17 @@ int SrsMp4Box::left_space(SrsBuffer* buf) | @@ -152,17 +108,17 @@ int SrsMp4Box::left_space(SrsBuffer* buf) | ||
| 152 | 108 | ||
| 153 | bool SrsMp4Box::is_ftyp() | 109 | bool SrsMp4Box::is_ftyp() |
| 154 | { | 110 | { |
| 155 | - return type == SRS_MP4_BOX_FTYP; | 111 | + return type == SrsMp4BoxTypeFTYP; |
| 156 | } | 112 | } |
| 157 | 113 | ||
| 158 | bool SrsMp4Box::is_moov() | 114 | bool SrsMp4Box::is_moov() |
| 159 | { | 115 | { |
| 160 | - return type == SRS_MP4_BOX_MOOV; | 116 | + return type == SrsMp4BoxTypeMOOV; |
| 161 | } | 117 | } |
| 162 | 118 | ||
| 163 | bool SrsMp4Box::is_mdat() | 119 | bool SrsMp4Box::is_mdat() |
| 164 | { | 120 | { |
| 165 | - return type == SRS_MP4_BOX_MDAT; | 121 | + return type == SrsMp4BoxTypeMDAT; |
| 166 | } | 122 | } |
| 167 | 123 | ||
| 168 | int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) | 124 | int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) |
| @@ -180,7 +136,7 @@ int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) | @@ -180,7 +136,7 @@ int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) | ||
| 180 | // Discovery the size and type. | 136 | // Discovery the size and type. |
| 181 | uint64_t largesize = 0; | 137 | uint64_t largesize = 0; |
| 182 | uint32_t smallsize = (uint32_t)buf->read_4bytes(); | 138 | uint32_t smallsize = (uint32_t)buf->read_4bytes(); |
| 183 | - uint32_t type = (uint32_t)buf->read_4bytes(); | 139 | + SrsMp4BoxType type = (SrsMp4BoxType)buf->read_4bytes(); |
| 184 | if (smallsize == SRS_MP4_USE_LARGE_SIZE) { | 140 | if (smallsize == SRS_MP4_USE_LARGE_SIZE) { |
| 185 | if (!buf->require(8)) { | 141 | if (!buf->require(8)) { |
| 186 | ret = ERROR_MP4_BOX_REQUIRE_SPACE; | 142 | ret = ERROR_MP4_BOX_REQUIRE_SPACE; |
| @@ -201,38 +157,38 @@ int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) | @@ -201,38 +157,38 @@ int SrsMp4Box::discovery(SrsBuffer* buf, SrsMp4Box** ppbox) | ||
| 201 | 157 | ||
| 202 | SrsMp4Box* box = NULL; | 158 | SrsMp4Box* box = NULL; |
| 203 | switch(type) { | 159 | switch(type) { |
| 204 | - case SRS_MP4_BOX_FTYP: box = new SrsMp4FileTypeBox(); break; | ||
| 205 | - case SRS_MP4_BOX_MDAT: box = new SrsMp4MediaDataBox(); break; | ||
| 206 | - case SRS_MP4_BOX_FREE: case SRS_MP4_BOX_SKIP: box = new SrsMp4FreeSpaceBox(); break; | ||
| 207 | - case SRS_MP4_BOX_MOOV: box = new SrsMp4MovieBox(); break; | ||
| 208 | - case SRS_MP4_BOX_MVHD: box = new SrsMp4MovieHeaderBox(); break; | ||
| 209 | - case SRS_MP4_BOX_TRAK: box = new SrsMp4TrackBox(); break; | ||
| 210 | - case SRS_MP4_BOX_TKHD: box = new SrsMp4TrackHeaderBox(); break; | ||
| 211 | - case SRS_MP4_BOX_EDTS: box = new SrsMp4EditBox(); break; | ||
| 212 | - case SRS_MP4_BOX_ELST: box = new SrsMp4EditListBox(); break; | ||
| 213 | - case SRS_MP4_BOX_MDIA: box = new SrsMp4MediaBox(); break; | ||
| 214 | - case SRS_MP4_BOX_MDHD: box = new SrsMp4MediaHeaderBox(); break; | ||
| 215 | - case SRS_MP4_BOX_HDLR: box = new SrsMp4HandlerReferenceBox(); break; | ||
| 216 | - case SRS_MP4_BOX_MINF: box = new SrsMp4MediaInformationBox(); break; | ||
| 217 | - case SRS_MP4_BOX_VMHD: box = new SrsMp4VideoMeidaHeaderBox(); break; | ||
| 218 | - case SRS_MP4_BOX_SMHD: box = new SrsMp4SoundMeidaHeaderBox(); break; | ||
| 219 | - case SRS_MP4_BOX_DINF: box = new SrsMp4DataInformationBox(); break; | ||
| 220 | - case SRS_MP4_BOX_URL: box = new SrsMp4DataEntryUrlBox(); break; | ||
| 221 | - case SRS_MP4_BOX_URN: box = new SrsMp4DataEntryUrnBox(); break; | ||
| 222 | - case SRS_MP4_BOX_DREF: box = new SrsMp4DataReferenceBox(); break; | ||
| 223 | - case SRS_MP4_BOX_STBL: box = new SrsMp4SampleTableBox(); break; | ||
| 224 | - case SRS_MP4_BOX_STSD: box = new SrsMp4SampleDescriptionBox(); break; | ||
| 225 | - case SRS_MP4_BOX_STTS: box = new SrsMp4DecodingTime2SampleBox(); break; | ||
| 226 | - case SRS_MP4_BOX_CTTS: box = new SrsMp4CompositionTime2SampleBox(); break; | ||
| 227 | - case SRS_MP4_BOX_STSS: box = new SrsMp4SyncSampleBox(); break; | ||
| 228 | - case SRS_MP4_BOX_STSC: box = new SrsMp4Sample2ChunkBox(); break; | ||
| 229 | - case SRS_MP4_BOX_STCO: box = new SrsMp4ChunkOffsetBox(); break; | ||
| 230 | - case SRS_MP4_BOX_CO64: box = new SrsMp4ChunkLargeOffsetBox(); break; | ||
| 231 | - case SRS_MP4_BOX_STSZ: box = new SrsMp4SampleSizeBox(); break; | ||
| 232 | - case SRS_MP4_BOX_AVC1: box = new SrsMp4VisualSampleEntry(); break; | ||
| 233 | - case SRS_MP4_BOX_AVCC: box = new SrsMp4AvccBox(); break; | ||
| 234 | - case SRS_MP4_BOX_MP4A: box = new SrsMp4AudioSampleEntry(); break; | ||
| 235 | - case SRS_MP4_BOX_ESDS: box = new SrsMp4EsdsBox(); break; | 160 | + case SrsMp4BoxTypeFTYP: box = new SrsMp4FileTypeBox(); break; |
| 161 | + case SrsMp4BoxTypeMDAT: box = new SrsMp4MediaDataBox(); break; | ||
| 162 | + case SrsMp4BoxTypeFREE: case SrsMp4BoxTypeSKIP: box = new SrsMp4FreeSpaceBox(); break; | ||
| 163 | + case SrsMp4BoxTypeMOOV: box = new SrsMp4MovieBox(); break; | ||
| 164 | + case SrsMp4BoxTypeMVHD: box = new SrsMp4MovieHeaderBox(); break; | ||
| 165 | + case SrsMp4BoxTypeTRAK: box = new SrsMp4TrackBox(); break; | ||
| 166 | + case SrsMp4BoxTypeTKHD: box = new SrsMp4TrackHeaderBox(); break; | ||
| 167 | + case SrsMp4BoxTypeEDTS: box = new SrsMp4EditBox(); break; | ||
| 168 | + case SrsMp4BoxTypeELST: box = new SrsMp4EditListBox(); break; | ||
| 169 | + case SrsMp4BoxTypeMDIA: box = new SrsMp4MediaBox(); break; | ||
| 170 | + case SrsMp4BoxTypeMDHD: box = new SrsMp4MediaHeaderBox(); break; | ||
| 171 | + case SrsMp4BoxTypeHDLR: box = new SrsMp4HandlerReferenceBox(); break; | ||
| 172 | + case SrsMp4BoxTypeMINF: box = new SrsMp4MediaInformationBox(); break; | ||
| 173 | + case SrsMp4BoxTypeVMHD: box = new SrsMp4VideoMeidaHeaderBox(); break; | ||
| 174 | + case SrsMp4BoxTypeSMHD: box = new SrsMp4SoundMeidaHeaderBox(); break; | ||
| 175 | + case SrsMp4BoxTypeDINF: box = new SrsMp4DataInformationBox(); break; | ||
| 176 | + case SrsMp4BoxTypeURL: box = new SrsMp4DataEntryUrlBox(); break; | ||
| 177 | + case SrsMp4BoxTypeURN: box = new SrsMp4DataEntryUrnBox(); break; | ||
| 178 | + case SrsMp4BoxTypeDREF: box = new SrsMp4DataReferenceBox(); break; | ||
| 179 | + case SrsMp4BoxTypeSTBL: box = new SrsMp4SampleTableBox(); break; | ||
| 180 | + case SrsMp4BoxTypeSTSD: box = new SrsMp4SampleDescriptionBox(); break; | ||
| 181 | + case SrsMp4BoxTypeSTTS: box = new SrsMp4DecodingTime2SampleBox(); break; | ||
| 182 | + case SrsMp4BoxTypeCTTS: box = new SrsMp4CompositionTime2SampleBox(); break; | ||
| 183 | + case SrsMp4BoxTypeSTSS: box = new SrsMp4SyncSampleBox(); break; | ||
| 184 | + case SrsMp4BoxTypeSTSC: box = new SrsMp4Sample2ChunkBox(); break; | ||
| 185 | + case SrsMp4BoxTypeSTCO: box = new SrsMp4ChunkOffsetBox(); break; | ||
| 186 | + case SrsMp4BoxTypeCO64: box = new SrsMp4ChunkLargeOffsetBox(); break; | ||
| 187 | + case SrsMp4BoxTypeSTSZ: box = new SrsMp4SampleSizeBox(); break; | ||
| 188 | + case SrsMp4BoxTypeAVC1: box = new SrsMp4VisualSampleEntry(); break; | ||
| 189 | + case SrsMp4BoxTypeAVCC: box = new SrsMp4AvccBox(); break; | ||
| 190 | + case SrsMp4BoxTypeMP4A: box = new SrsMp4AudioSampleEntry(); break; | ||
| 191 | + case SrsMp4BoxTypeESDS: box = new SrsMp4EsdsBox(); break; | ||
| 236 | default: | 192 | default: |
| 237 | ret = ERROR_MP4_BOX_ILLEGAL_TYPE; | 193 | ret = ERROR_MP4_BOX_ILLEGAL_TYPE; |
| 238 | srs_error("MP4 illegal box type=%d. ret=%d", type, ret); | 194 | srs_error("MP4 illegal box type=%d. ret=%d", type, ret); |
| @@ -347,7 +303,7 @@ int SrsMp4Box::nb_header() | @@ -347,7 +303,7 @@ int SrsMp4Box::nb_header() | ||
| 347 | size += 8; | 303 | size += 8; |
| 348 | } | 304 | } |
| 349 | 305 | ||
| 350 | - if (type == SRS_MP4_BOX_UUID) { | 306 | + if (type == SrsMp4BoxTypeUUID) { |
| 351 | size += 16; | 307 | size += 16; |
| 352 | } | 308 | } |
| 353 | 309 | ||
| @@ -378,7 +334,7 @@ int SrsMp4Box::encode_header(SrsBuffer* buf) | @@ -378,7 +334,7 @@ int SrsMp4Box::encode_header(SrsBuffer* buf) | ||
| 378 | } | 334 | } |
| 379 | buf->write_4bytes(type); | 335 | buf->write_4bytes(type); |
| 380 | 336 | ||
| 381 | - if (type == SRS_MP4_BOX_UUID) { | 337 | + if (type == SrsMp4BoxTypeUUID) { |
| 382 | buf->write_bytes((char*)usertype, 16); | 338 | buf->write_bytes((char*)usertype, 16); |
| 383 | } | 339 | } |
| 384 | 340 | ||
| @@ -395,7 +351,7 @@ int SrsMp4Box::decode_header(SrsBuffer* buf) | @@ -395,7 +351,7 @@ int SrsMp4Box::decode_header(SrsBuffer* buf) | ||
| 395 | return ret; | 351 | return ret; |
| 396 | } | 352 | } |
| 397 | smallsize = (uint32_t)buf->read_4bytes(); | 353 | smallsize = (uint32_t)buf->read_4bytes(); |
| 398 | - type = (uint32_t)buf->read_4bytes(); | 354 | + type = (SrsMp4BoxType)buf->read_4bytes(); |
| 399 | 355 | ||
| 400 | if (smallsize == SRS_MP4_EOF_SIZE) { | 356 | if (smallsize == SRS_MP4_EOF_SIZE) { |
| 401 | srs_warn("MP4 box EOF."); | 357 | srs_warn("MP4 box EOF."); |
| @@ -418,7 +374,7 @@ int SrsMp4Box::decode_header(SrsBuffer* buf) | @@ -418,7 +374,7 @@ int SrsMp4Box::decode_header(SrsBuffer* buf) | ||
| 418 | return ret; | 374 | return ret; |
| 419 | } | 375 | } |
| 420 | 376 | ||
| 421 | - if (type == SRS_MP4_BOX_UUID) { | 377 | + if (type == SrsMp4BoxTypeUUID) { |
| 422 | if (!buf->require(16)) { | 378 | if (!buf->require(16)) { |
| 423 | ret = ERROR_MP4_BOX_REQUIRE_SPACE; | 379 | ret = ERROR_MP4_BOX_REQUIRE_SPACE; |
| 424 | srs_error("MP4 box requires 16 bytes space. ret=%d", ret); | 380 | srs_error("MP4 box requires 16 bytes space. ret=%d", ret); |
| @@ -500,10 +456,11 @@ int SrsMp4FullBox::decode_header(SrsBuffer* buf) | @@ -500,10 +456,11 @@ int SrsMp4FullBox::decode_header(SrsBuffer* buf) | ||
| 500 | 456 | ||
| 501 | SrsMp4FileTypeBox::SrsMp4FileTypeBox() | 457 | SrsMp4FileTypeBox::SrsMp4FileTypeBox() |
| 502 | { | 458 | { |
| 503 | - type = SRS_MP4_BOX_FTYP; | 459 | + type = SrsMp4BoxTypeFTYP; |
| 504 | nb_compatible_brands = 0; | 460 | nb_compatible_brands = 0; |
| 505 | compatible_brands = NULL; | 461 | compatible_brands = NULL; |
| 506 | - major_brand = minor_version = 0; | 462 | + major_brand = SrsMp4BoxBrandForbidden; |
| 463 | + minor_version = 0; | ||
| 507 | } | 464 | } |
| 508 | 465 | ||
| 509 | SrsMp4FileTypeBox::~SrsMp4FileTypeBox() | 466 | SrsMp4FileTypeBox::~SrsMp4FileTypeBox() |
| @@ -528,8 +485,7 @@ int SrsMp4FileTypeBox::encode_header(SrsBuffer* buf) | @@ -528,8 +485,7 @@ int SrsMp4FileTypeBox::encode_header(SrsBuffer* buf) | ||
| 528 | buf->write_4bytes(minor_version); | 485 | buf->write_4bytes(minor_version); |
| 529 | 486 | ||
| 530 | for (int i = 0; i < nb_compatible_brands; i++) { | 487 | for (int i = 0; i < nb_compatible_brands; i++) { |
| 531 | - uint32_t& cb = compatible_brands[i]; | ||
| 532 | - buf->write_4bytes(cb); | 488 | + buf->write_4bytes(compatible_brands[i]); |
| 533 | } | 489 | } |
| 534 | 490 | ||
| 535 | return ret; | 491 | return ret; |
| @@ -543,7 +499,7 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | @@ -543,7 +499,7 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | ||
| 543 | return ret; | 499 | return ret; |
| 544 | } | 500 | } |
| 545 | 501 | ||
| 546 | - major_brand = buf->read_4bytes(); | 502 | + major_brand = (SrsMp4BoxBrand)buf->read_4bytes(); |
| 547 | minor_version = buf->read_4bytes(); | 503 | minor_version = buf->read_4bytes(); |
| 548 | 504 | ||
| 549 | // Compatible brands to the end of the box. | 505 | // Compatible brands to the end of the box. |
| @@ -551,12 +507,11 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | @@ -551,12 +507,11 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | ||
| 551 | 507 | ||
| 552 | if (left > 0) { | 508 | if (left > 0) { |
| 553 | nb_compatible_brands = left / 4; | 509 | nb_compatible_brands = left / 4; |
| 554 | - compatible_brands = new uint32_t[nb_compatible_brands]; | 510 | + compatible_brands = new SrsMp4BoxBrand[nb_compatible_brands]; |
| 555 | } | 511 | } |
| 556 | 512 | ||
| 557 | for (int i = 0; left > 0; i++, left -= 4){ | 513 | for (int i = 0; left > 0; i++, left -= 4){ |
| 558 | - uint32_t cb = buf->read_4bytes(); | ||
| 559 | - compatible_brands[i] = cb; | 514 | + compatible_brands[i] = (SrsMp4BoxBrand)buf->read_4bytes(); |
| 560 | } | 515 | } |
| 561 | 516 | ||
| 562 | return ret; | 517 | return ret; |
| @@ -564,7 +519,7 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | @@ -564,7 +519,7 @@ int SrsMp4FileTypeBox::decode_header(SrsBuffer* buf) | ||
| 564 | 519 | ||
| 565 | SrsMp4MediaDataBox::SrsMp4MediaDataBox() | 520 | SrsMp4MediaDataBox::SrsMp4MediaDataBox() |
| 566 | { | 521 | { |
| 567 | - type = SRS_MP4_BOX_MDAT; | 522 | + type = SrsMp4BoxTypeMDAT; |
| 568 | data = NULL; | 523 | data = NULL; |
| 569 | nb_data = 0; | 524 | nb_data = 0; |
| 570 | } | 525 | } |
| @@ -613,7 +568,7 @@ int SrsMp4MediaDataBox::decode_header(SrsBuffer* buf) | @@ -613,7 +568,7 @@ int SrsMp4MediaDataBox::decode_header(SrsBuffer* buf) | ||
| 613 | 568 | ||
| 614 | SrsMp4FreeSpaceBox::SrsMp4FreeSpaceBox() | 569 | SrsMp4FreeSpaceBox::SrsMp4FreeSpaceBox() |
| 615 | { | 570 | { |
| 616 | - type = SRS_MP4_BOX_FREE; // 'free' or 'skip' | 571 | + type = SrsMp4BoxTypeFREE; // 'free' or 'skip' |
| 617 | data = NULL; | 572 | data = NULL; |
| 618 | nb_data = 0; | 573 | nb_data = 0; |
| 619 | } | 574 | } |
| @@ -662,7 +617,7 @@ int SrsMp4FreeSpaceBox::decode_header(SrsBuffer* buf) | @@ -662,7 +617,7 @@ int SrsMp4FreeSpaceBox::decode_header(SrsBuffer* buf) | ||
| 662 | 617 | ||
| 663 | SrsMp4MovieBox::SrsMp4MovieBox() | 618 | SrsMp4MovieBox::SrsMp4MovieBox() |
| 664 | { | 619 | { |
| 665 | - type = SRS_MP4_BOX_MOOV; | 620 | + type = SrsMp4BoxTypeMOOV; |
| 666 | } | 621 | } |
| 667 | 622 | ||
| 668 | SrsMp4MovieBox::~SrsMp4MovieBox() | 623 | SrsMp4MovieBox::~SrsMp4MovieBox() |
| @@ -671,7 +626,7 @@ SrsMp4MovieBox::~SrsMp4MovieBox() | @@ -671,7 +626,7 @@ SrsMp4MovieBox::~SrsMp4MovieBox() | ||
| 671 | 626 | ||
| 672 | SrsMp4MovieHeaderBox::SrsMp4MovieHeaderBox() | 627 | SrsMp4MovieHeaderBox::SrsMp4MovieHeaderBox() |
| 673 | { | 628 | { |
| 674 | - type = SRS_MP4_BOX_MVHD; | 629 | + type = SrsMp4BoxTypeMVHD; |
| 675 | 630 | ||
| 676 | rate = 0x00010000; // typically 1.0 | 631 | rate = 0x00010000; // typically 1.0 |
| 677 | volume = 0x0100; // typically, full volume | 632 | volume = 0x0100; // typically, full volume |
| @@ -773,7 +728,7 @@ int SrsMp4MovieHeaderBox::decode_header(SrsBuffer* buf) | @@ -773,7 +728,7 @@ int SrsMp4MovieHeaderBox::decode_header(SrsBuffer* buf) | ||
| 773 | 728 | ||
| 774 | SrsMp4TrackBox::SrsMp4TrackBox() | 729 | SrsMp4TrackBox::SrsMp4TrackBox() |
| 775 | { | 730 | { |
| 776 | - type = SRS_MP4_BOX_TRAK; | 731 | + type = SrsMp4BoxTypeTRAK; |
| 777 | } | 732 | } |
| 778 | 733 | ||
| 779 | SrsMp4TrackBox::~SrsMp4TrackBox() | 734 | SrsMp4TrackBox::~SrsMp4TrackBox() |
| @@ -782,7 +737,7 @@ SrsMp4TrackBox::~SrsMp4TrackBox() | @@ -782,7 +737,7 @@ SrsMp4TrackBox::~SrsMp4TrackBox() | ||
| 782 | 737 | ||
| 783 | SrsMp4TrackHeaderBox::SrsMp4TrackHeaderBox() | 738 | SrsMp4TrackHeaderBox::SrsMp4TrackHeaderBox() |
| 784 | { | 739 | { |
| 785 | - type = SRS_MP4_BOX_TKHD; | 740 | + type = SrsMp4BoxTypeTKHD; |
| 786 | 741 | ||
| 787 | reserved0 = 0; | 742 | reserved0 = 0; |
| 788 | reserved1 = 0; | 743 | reserved1 = 0; |
| @@ -887,7 +842,7 @@ int SrsMp4TrackHeaderBox::decode_header(SrsBuffer* buf) | @@ -887,7 +842,7 @@ int SrsMp4TrackHeaderBox::decode_header(SrsBuffer* buf) | ||
| 887 | 842 | ||
| 888 | SrsMp4EditBox::SrsMp4EditBox() | 843 | SrsMp4EditBox::SrsMp4EditBox() |
| 889 | { | 844 | { |
| 890 | - type = SRS_MP4_BOX_EDTS; | 845 | + type = SrsMp4BoxTypeEDTS; |
| 891 | } | 846 | } |
| 892 | 847 | ||
| 893 | SrsMp4EditBox::~SrsMp4EditBox() | 848 | SrsMp4EditBox::~SrsMp4EditBox() |
| @@ -901,7 +856,7 @@ SrsMp4ElstEntry::SrsMp4ElstEntry() | @@ -901,7 +856,7 @@ SrsMp4ElstEntry::SrsMp4ElstEntry() | ||
| 901 | 856 | ||
| 902 | SrsMp4EditListBox::SrsMp4EditListBox() | 857 | SrsMp4EditListBox::SrsMp4EditListBox() |
| 903 | { | 858 | { |
| 904 | - type = SRS_MP4_BOX_ELST; | 859 | + type = SrsMp4BoxTypeELST; |
| 905 | 860 | ||
| 906 | entry_count = 0; | 861 | entry_count = 0; |
| 907 | entries = NULL; | 862 | entries = NULL; |
| @@ -984,7 +939,7 @@ int SrsMp4EditListBox::decode_header(SrsBuffer* buf) | @@ -984,7 +939,7 @@ int SrsMp4EditListBox::decode_header(SrsBuffer* buf) | ||
| 984 | 939 | ||
| 985 | SrsMp4MediaBox::SrsMp4MediaBox() | 940 | SrsMp4MediaBox::SrsMp4MediaBox() |
| 986 | { | 941 | { |
| 987 | - type = SRS_MP4_BOX_MDIA; | 942 | + type = SrsMp4BoxTypeMDIA; |
| 988 | } | 943 | } |
| 989 | 944 | ||
| 990 | SrsMp4MediaBox::~SrsMp4MediaBox() | 945 | SrsMp4MediaBox::~SrsMp4MediaBox() |
| @@ -993,7 +948,7 @@ SrsMp4MediaBox::~SrsMp4MediaBox() | @@ -993,7 +948,7 @@ SrsMp4MediaBox::~SrsMp4MediaBox() | ||
| 993 | 948 | ||
| 994 | SrsMp4MediaHeaderBox::SrsMp4MediaHeaderBox() | 949 | SrsMp4MediaHeaderBox::SrsMp4MediaHeaderBox() |
| 995 | { | 950 | { |
| 996 | - type = SRS_MP4_BOX_MDHD; | 951 | + type = SrsMp4BoxTypeMDHD; |
| 997 | language = 0; | 952 | language = 0; |
| 998 | pre_defined = 0; | 953 | pre_defined = 0; |
| 999 | } | 954 | } |
| @@ -1101,7 +1056,7 @@ int SrsMp4MediaHeaderBox::decode_header(SrsBuffer* buf) | @@ -1101,7 +1056,7 @@ int SrsMp4MediaHeaderBox::decode_header(SrsBuffer* buf) | ||
| 1101 | 1056 | ||
| 1102 | SrsMp4HandlerReferenceBox::SrsMp4HandlerReferenceBox() | 1057 | SrsMp4HandlerReferenceBox::SrsMp4HandlerReferenceBox() |
| 1103 | { | 1058 | { |
| 1104 | - type = SRS_MP4_BOX_HDLR; | 1059 | + type = SrsMp4BoxTypeHDLR; |
| 1105 | 1060 | ||
| 1106 | pre_defined = 0; | 1061 | pre_defined = 0; |
| 1107 | memset(reserved, 0, 12); | 1062 | memset(reserved, 0, 12); |
| @@ -1113,12 +1068,12 @@ SrsMp4HandlerReferenceBox::~SrsMp4HandlerReferenceBox() | @@ -1113,12 +1068,12 @@ SrsMp4HandlerReferenceBox::~SrsMp4HandlerReferenceBox() | ||
| 1113 | 1068 | ||
| 1114 | bool SrsMp4HandlerReferenceBox::is_video() | 1069 | bool SrsMp4HandlerReferenceBox::is_video() |
| 1115 | { | 1070 | { |
| 1116 | - return handler_type == SRS_MP4_HANDLER_VIDE; | 1071 | + return handler_type == SrsMp4BoxTypeVIDE; |
| 1117 | } | 1072 | } |
| 1118 | 1073 | ||
| 1119 | bool SrsMp4HandlerReferenceBox::is_audio() | 1074 | bool SrsMp4HandlerReferenceBox::is_audio() |
| 1120 | { | 1075 | { |
| 1121 | - return handler_type == SRS_MP4_HANDLER_SOUN; | 1076 | + return handler_type == SrsMp4BoxTypeSOUN; |
| 1122 | } | 1077 | } |
| 1123 | 1078 | ||
| 1124 | int SrsMp4HandlerReferenceBox::nb_header() | 1079 | int SrsMp4HandlerReferenceBox::nb_header() |
| @@ -1166,7 +1121,7 @@ int SrsMp4HandlerReferenceBox::decode_header(SrsBuffer* buf) | @@ -1166,7 +1121,7 @@ int SrsMp4HandlerReferenceBox::decode_header(SrsBuffer* buf) | ||
| 1166 | 1121 | ||
| 1167 | SrsMp4MediaInformationBox::SrsMp4MediaInformationBox() | 1122 | SrsMp4MediaInformationBox::SrsMp4MediaInformationBox() |
| 1168 | { | 1123 | { |
| 1169 | - type = SRS_MP4_BOX_MINF; | 1124 | + type = SrsMp4BoxTypeMINF; |
| 1170 | } | 1125 | } |
| 1171 | 1126 | ||
| 1172 | SrsMp4MediaInformationBox::~SrsMp4MediaInformationBox() | 1127 | SrsMp4MediaInformationBox::~SrsMp4MediaInformationBox() |
| @@ -1175,7 +1130,7 @@ SrsMp4MediaInformationBox::~SrsMp4MediaInformationBox() | @@ -1175,7 +1130,7 @@ SrsMp4MediaInformationBox::~SrsMp4MediaInformationBox() | ||
| 1175 | 1130 | ||
| 1176 | SrsMp4VideoMeidaHeaderBox::SrsMp4VideoMeidaHeaderBox() | 1131 | SrsMp4VideoMeidaHeaderBox::SrsMp4VideoMeidaHeaderBox() |
| 1177 | { | 1132 | { |
| 1178 | - type = SRS_MP4_BOX_VMHD; | 1133 | + type = SrsMp4BoxTypeVMHD; |
| 1179 | version = 0; | 1134 | version = 0; |
| 1180 | flags = 1; | 1135 | flags = 1; |
| 1181 | 1136 | ||
| @@ -1226,7 +1181,7 @@ int SrsMp4VideoMeidaHeaderBox::decode_header(SrsBuffer* buf) | @@ -1226,7 +1181,7 @@ int SrsMp4VideoMeidaHeaderBox::decode_header(SrsBuffer* buf) | ||
| 1226 | 1181 | ||
| 1227 | SrsMp4SoundMeidaHeaderBox::SrsMp4SoundMeidaHeaderBox() | 1182 | SrsMp4SoundMeidaHeaderBox::SrsMp4SoundMeidaHeaderBox() |
| 1228 | { | 1183 | { |
| 1229 | - type = SRS_MP4_BOX_SMHD; | 1184 | + type = SrsMp4BoxTypeSMHD; |
| 1230 | 1185 | ||
| 1231 | reserved = balance = 0; | 1186 | reserved = balance = 0; |
| 1232 | } | 1187 | } |
| @@ -1270,7 +1225,7 @@ int SrsMp4SoundMeidaHeaderBox::decode_header(SrsBuffer* buf) | @@ -1270,7 +1225,7 @@ int SrsMp4SoundMeidaHeaderBox::decode_header(SrsBuffer* buf) | ||
| 1270 | 1225 | ||
| 1271 | SrsMp4DataInformationBox::SrsMp4DataInformationBox() | 1226 | SrsMp4DataInformationBox::SrsMp4DataInformationBox() |
| 1272 | { | 1227 | { |
| 1273 | - type = SRS_MP4_BOX_DINF; | 1228 | + type = SrsMp4BoxTypeDINF; |
| 1274 | } | 1229 | } |
| 1275 | 1230 | ||
| 1276 | SrsMp4DataInformationBox::~SrsMp4DataInformationBox() | 1231 | SrsMp4DataInformationBox::~SrsMp4DataInformationBox() |
| @@ -1287,7 +1242,7 @@ SrsMp4DataEntryBox::~SrsMp4DataEntryBox() | @@ -1287,7 +1242,7 @@ SrsMp4DataEntryBox::~SrsMp4DataEntryBox() | ||
| 1287 | 1242 | ||
| 1288 | SrsMp4DataEntryUrlBox::SrsMp4DataEntryUrlBox() | 1243 | SrsMp4DataEntryUrlBox::SrsMp4DataEntryUrlBox() |
| 1289 | { | 1244 | { |
| 1290 | - type = SRS_MP4_BOX_URL; | 1245 | + type = SrsMp4BoxTypeURL; |
| 1291 | } | 1246 | } |
| 1292 | 1247 | ||
| 1293 | SrsMp4DataEntryUrlBox::~SrsMp4DataEntryUrlBox() | 1248 | SrsMp4DataEntryUrlBox::~SrsMp4DataEntryUrlBox() |
| @@ -1348,7 +1303,7 @@ int SrsMp4DataEntryUrlBox::decode_header(SrsBuffer* buf) | @@ -1348,7 +1303,7 @@ int SrsMp4DataEntryUrlBox::decode_header(SrsBuffer* buf) | ||
| 1348 | 1303 | ||
| 1349 | SrsMp4DataEntryUrnBox::SrsMp4DataEntryUrnBox() | 1304 | SrsMp4DataEntryUrnBox::SrsMp4DataEntryUrnBox() |
| 1350 | { | 1305 | { |
| 1351 | - type = SRS_MP4_BOX_URN; | 1306 | + type = SrsMp4BoxTypeURN; |
| 1352 | } | 1307 | } |
| 1353 | 1308 | ||
| 1354 | SrsMp4DataEntryUrnBox::~SrsMp4DataEntryUrnBox() | 1309 | SrsMp4DataEntryUrnBox::~SrsMp4DataEntryUrnBox() |
| @@ -1397,7 +1352,7 @@ int SrsMp4DataEntryUrnBox::decode_header(SrsBuffer* buf) | @@ -1397,7 +1352,7 @@ int SrsMp4DataEntryUrnBox::decode_header(SrsBuffer* buf) | ||
| 1397 | 1352 | ||
| 1398 | SrsMp4DataReferenceBox::SrsMp4DataReferenceBox() | 1353 | SrsMp4DataReferenceBox::SrsMp4DataReferenceBox() |
| 1399 | { | 1354 | { |
| 1400 | - type = SRS_MP4_BOX_DREF; | 1355 | + type = SrsMp4BoxTypeDREF; |
| 1401 | } | 1356 | } |
| 1402 | 1357 | ||
| 1403 | SrsMp4DataReferenceBox::~SrsMp4DataReferenceBox() | 1358 | SrsMp4DataReferenceBox::~SrsMp4DataReferenceBox() |
| @@ -1481,9 +1436,9 @@ int SrsMp4DataReferenceBox::decode_header(SrsBuffer* buf) | @@ -1481,9 +1436,9 @@ int SrsMp4DataReferenceBox::decode_header(SrsBuffer* buf) | ||
| 1481 | fbox->flags = flags; | 1436 | fbox->flags = flags; |
| 1482 | } | 1437 | } |
| 1483 | 1438 | ||
| 1484 | - if (box->type == SRS_MP4_BOX_URL) { | 1439 | + if (box->type == SrsMp4BoxTypeURL) { |
| 1485 | entries.push_back(dynamic_cast<SrsMp4DataEntryUrlBox*>(box)); | 1440 | entries.push_back(dynamic_cast<SrsMp4DataEntryUrlBox*>(box)); |
| 1486 | - } else if (box->type == SRS_MP4_BOX_URN) { | 1441 | + } else if (box->type == SrsMp4BoxTypeURN) { |
| 1487 | entries.push_back(dynamic_cast<SrsMp4DataEntryUrnBox*>(box)); | 1442 | entries.push_back(dynamic_cast<SrsMp4DataEntryUrnBox*>(box)); |
| 1488 | } else { | 1443 | } else { |
| 1489 | srs_freep(box); | 1444 | srs_freep(box); |
| @@ -1495,7 +1450,7 @@ int SrsMp4DataReferenceBox::decode_header(SrsBuffer* buf) | @@ -1495,7 +1450,7 @@ int SrsMp4DataReferenceBox::decode_header(SrsBuffer* buf) | ||
| 1495 | 1450 | ||
| 1496 | SrsMp4SampleTableBox::SrsMp4SampleTableBox() | 1451 | SrsMp4SampleTableBox::SrsMp4SampleTableBox() |
| 1497 | { | 1452 | { |
| 1498 | - type = SRS_MP4_BOX_STBL; | 1453 | + type = SrsMp4BoxTypeSTBL; |
| 1499 | } | 1454 | } |
| 1500 | 1455 | ||
| 1501 | SrsMp4SampleTableBox::~SrsMp4SampleTableBox() | 1456 | SrsMp4SampleTableBox::~SrsMp4SampleTableBox() |
| @@ -1621,7 +1576,7 @@ int SrsMp4VisualSampleEntry::decode_header(SrsBuffer* buf) | @@ -1621,7 +1576,7 @@ int SrsMp4VisualSampleEntry::decode_header(SrsBuffer* buf) | ||
| 1621 | 1576 | ||
| 1622 | SrsMp4AvccBox::SrsMp4AvccBox() | 1577 | SrsMp4AvccBox::SrsMp4AvccBox() |
| 1623 | { | 1578 | { |
| 1624 | - type = SRS_MP4_BOX_AVCC; | 1579 | + type = SrsMp4BoxTypeAVCC; |
| 1625 | nb_config = 0; | 1580 | nb_config = 0; |
| 1626 | avc_config = NULL; | 1581 | avc_config = NULL; |
| 1627 | } | 1582 | } |
| @@ -1724,20 +1679,27 @@ int SrsMp4AudioSampleEntry::decode_header(SrsBuffer* buf) | @@ -1724,20 +1679,27 @@ int SrsMp4AudioSampleEntry::decode_header(SrsBuffer* buf) | ||
| 1724 | 1679 | ||
| 1725 | SrsMp4BaseDescriptor::SrsMp4BaseDescriptor() | 1680 | SrsMp4BaseDescriptor::SrsMp4BaseDescriptor() |
| 1726 | { | 1681 | { |
| 1727 | - tag = SRS_MP4_ES_TAG_ES_forbidden; | 1682 | + tag = SrsMp4ESTagESforbidden; |
| 1683 | + vlen = -1; | ||
| 1684 | + start_pos = 0; | ||
| 1728 | } | 1685 | } |
| 1729 | 1686 | ||
| 1730 | SrsMp4BaseDescriptor::~SrsMp4BaseDescriptor() | 1687 | SrsMp4BaseDescriptor::~SrsMp4BaseDescriptor() |
| 1731 | { | 1688 | { |
| 1732 | } | 1689 | } |
| 1733 | 1690 | ||
| 1691 | +int SrsMp4BaseDescriptor::left_space(SrsBuffer* buf) | ||
| 1692 | +{ | ||
| 1693 | + return vlen - (buf->pos() - start_pos); | ||
| 1694 | +} | ||
| 1695 | + | ||
| 1734 | int SrsMp4BaseDescriptor::nb_bytes() | 1696 | int SrsMp4BaseDescriptor::nb_bytes() |
| 1735 | { | 1697 | { |
| 1736 | // 1 byte tag. | 1698 | // 1 byte tag. |
| 1737 | int size = 1; | 1699 | int size = 1; |
| 1738 | 1700 | ||
| 1739 | // 1-3 bytes size. | 1701 | // 1-3 bytes size. |
| 1740 | - uint32_t length = nb_payload(); | 1702 | + int32_t length = vlen = nb_payload(); // bit(8) to bit(32) |
| 1741 | if (length > 0x1fffff) { | 1703 | if (length > 0x1fffff) { |
| 1742 | size += 4; | 1704 | size += 4; |
| 1743 | } else if (length > 0x3fff) { | 1705 | } else if (length > 0x3fff) { |
| @@ -1769,7 +1731,23 @@ int SrsMp4BaseDescriptor::encode(SrsBuffer* buf) | @@ -1769,7 +1731,23 @@ int SrsMp4BaseDescriptor::encode(SrsBuffer* buf) | ||
| 1769 | 1731 | ||
| 1770 | // As an expandable class the size of each class instance in bytes is encoded and accessible | 1732 | // As an expandable class the size of each class instance in bytes is encoded and accessible |
| 1771 | // through the instance variable sizeOfInstance (see 8.3.3). | 1733 | // through the instance variable sizeOfInstance (see 8.3.3). |
| 1772 | - uint32_t length = nb_payload(); // bit(8) to bit(32) | 1734 | + int32_t length = vlen; // bit(8) to bit(32) |
| 1735 | + srs_assert(vlen > 0); | ||
| 1736 | + | ||
| 1737 | + if (length > 0x1fffff) { | ||
| 1738 | + buf->write_1bytes(uint8_t(length>>21)|0x80); | ||
| 1739 | + } | ||
| 1740 | + if (length > 0x3fff) { | ||
| 1741 | + buf->write_1bytes(uint8_t(length>>14)|0x80); | ||
| 1742 | + } | ||
| 1743 | + if (length > 0x7f) { | ||
| 1744 | + buf->write_1bytes(uint8_t(length>>7)|0x80); | ||
| 1745 | + } | ||
| 1746 | + buf->write_1bytes(length&0x7f); | ||
| 1747 | + | ||
| 1748 | + if ((ret = encode_payload(buf)) != ERROR_SUCCESS) { | ||
| 1749 | + return ret; | ||
| 1750 | + } | ||
| 1773 | 1751 | ||
| 1774 | return ret; | 1752 | return ret; |
| 1775 | } | 1753 | } |
| @@ -1785,65 +1763,184 @@ int SrsMp4BaseDescriptor::decode(SrsBuffer* buf) | @@ -1785,65 +1763,184 @@ int SrsMp4BaseDescriptor::decode(SrsBuffer* buf) | ||
| 1785 | return ret; | 1763 | return ret; |
| 1786 | } | 1764 | } |
| 1787 | 1765 | ||
| 1788 | - tag = (SRS_MP4_ES_TAG_ES)buf->read_1bytes(); | 1766 | + tag = (SrsMp4ESTagEs)buf->read_1bytes(); |
| 1767 | + | ||
| 1768 | + uint8_t v = 0x80; | ||
| 1769 | + int32_t length = 0x00; | ||
| 1770 | + while ((v&0x80) == 0x80) { | ||
| 1771 | + if (!buf->require(1)) { | ||
| 1772 | + ret = ERROR_MP4_BOX_REQUIRE_SPACE; | ||
| 1773 | + srs_error("MP4 ES requires 1 byte space. ret=%d", ret); | ||
| 1774 | + return ret; | ||
| 1775 | + } | ||
| 1776 | + v = buf->read_1bytes(); | ||
| 1777 | + | ||
| 1778 | + length = (length<<7) | (v&0x7f); | ||
| 1779 | + } | ||
| 1780 | + vlen = length; | ||
| 1781 | + | ||
| 1782 | + if (!buf->require(vlen)) { | ||
| 1783 | + ret = ERROR_MP4_BOX_REQUIRE_SPACE; | ||
| 1784 | + srs_error("MP4 ES requires %d bytes space. ret=%d", vlen, ret); | ||
| 1785 | + return ret; | ||
| 1786 | + } | ||
| 1787 | + | ||
| 1788 | + start_pos = buf->pos(); | ||
| 1789 | + | ||
| 1790 | + if ((ret = decode_payload(buf)) != ERROR_SUCCESS) { | ||
| 1791 | + return ret; | ||
| 1792 | + } | ||
| 1793 | + | ||
| 1794 | + return ret; | ||
| 1795 | +} | ||
| 1796 | + | ||
| 1797 | +SrsMp4DecoderSpecificInfo::SrsMp4DecoderSpecificInfo() | ||
| 1798 | +{ | ||
| 1799 | + tag = SrsMp4ESTagESDecSpecificInfoTag; | ||
| 1800 | + nb_asc = 0; | ||
| 1801 | + asc = NULL; | ||
| 1802 | +} | ||
| 1803 | + | ||
| 1804 | +SrsMp4DecoderSpecificInfo::~SrsMp4DecoderSpecificInfo() | ||
| 1805 | +{ | ||
| 1806 | + srs_freepa(asc); | ||
| 1807 | +} | ||
| 1808 | + | ||
| 1809 | +int32_t SrsMp4DecoderSpecificInfo::nb_payload() | ||
| 1810 | +{ | ||
| 1811 | + return nb_asc; | ||
| 1812 | +} | ||
| 1813 | + | ||
| 1814 | +int SrsMp4DecoderSpecificInfo::encode_payload(SrsBuffer* buf) | ||
| 1815 | +{ | ||
| 1816 | + int ret = ERROR_SUCCESS; | ||
| 1817 | + | ||
| 1818 | + if (nb_asc) { | ||
| 1819 | + buf->write_bytes((char*)asc, nb_asc); | ||
| 1820 | + } | ||
| 1821 | + | ||
| 1822 | + return ret; | ||
| 1823 | +} | ||
| 1824 | + | ||
| 1825 | +int SrsMp4DecoderSpecificInfo::decode_payload(SrsBuffer* buf) | ||
| 1826 | +{ | ||
| 1827 | + int ret = ERROR_SUCCESS; | ||
| 1828 | + | ||
| 1829 | + nb_asc = vlen; | ||
| 1830 | + if (nb_asc) { | ||
| 1831 | + asc = new uint8_t[nb_asc]; | ||
| 1832 | + buf->read_bytes((char*)asc, nb_asc); | ||
| 1833 | + } | ||
| 1834 | + | ||
| 1789 | return ret; | 1835 | return ret; |
| 1790 | } | 1836 | } |
| 1791 | 1837 | ||
| 1792 | SrsMp4DecoderConfigDescriptor::SrsMp4DecoderConfigDescriptor() | 1838 | SrsMp4DecoderConfigDescriptor::SrsMp4DecoderConfigDescriptor() |
| 1793 | { | 1839 | { |
| 1794 | - tag = SRS_MP4_ES_TAG_ES_DecoderConfigDescrTag; | 1840 | + tag = SrsMp4ESTagESDecoderConfigDescrTag; |
| 1841 | + objectTypeIndication = SrsMp4ObjectTypeForbidden; | ||
| 1842 | + streamType = SrsMp4StreamTypeForbidden; | ||
| 1843 | + decSpecificInfo = NULL; | ||
| 1844 | + reserved = 1; | ||
| 1795 | } | 1845 | } |
| 1796 | 1846 | ||
| 1797 | SrsMp4DecoderConfigDescriptor::~SrsMp4DecoderConfigDescriptor() | 1847 | SrsMp4DecoderConfigDescriptor::~SrsMp4DecoderConfigDescriptor() |
| 1798 | { | 1848 | { |
| 1849 | + srs_freep(decSpecificInfo); | ||
| 1799 | } | 1850 | } |
| 1800 | 1851 | ||
| 1801 | -uint32_t SrsMp4DecoderConfigDescriptor::nb_payload() | 1852 | +int32_t SrsMp4DecoderConfigDescriptor::nb_payload() |
| 1802 | { | 1853 | { |
| 1803 | - return 0; | 1854 | + return 12 + (decSpecificInfo? decSpecificInfo->nb_bytes():0); |
| 1804 | } | 1855 | } |
| 1805 | 1856 | ||
| 1806 | int SrsMp4DecoderConfigDescriptor::encode_payload(SrsBuffer* buf) | 1857 | int SrsMp4DecoderConfigDescriptor::encode_payload(SrsBuffer* buf) |
| 1807 | { | 1858 | { |
| 1808 | int ret = ERROR_SUCCESS; | 1859 | int ret = ERROR_SUCCESS; |
| 1860 | + | ||
| 1861 | + buf->write_1bytes(objectTypeIndication); | ||
| 1862 | + | ||
| 1863 | + uint8_t v = reserved; | ||
| 1864 | + v |= (upStream&0x01)<<1; | ||
| 1865 | + v |= uint8_t(streamType&0x3f)<<2; | ||
| 1866 | + buf->write_1bytes(v); | ||
| 1867 | + | ||
| 1868 | + buf->write_3bytes(bufferSizeDB); | ||
| 1869 | + buf->write_4bytes(maxBitrate); | ||
| 1870 | + buf->write_4bytes(avgBitrate); | ||
| 1871 | + | ||
| 1809 | return ret; | 1872 | return ret; |
| 1810 | } | 1873 | } |
| 1811 | 1874 | ||
| 1812 | int SrsMp4DecoderConfigDescriptor::decode_payload(SrsBuffer* buf) | 1875 | int SrsMp4DecoderConfigDescriptor::decode_payload(SrsBuffer* buf) |
| 1813 | { | 1876 | { |
| 1814 | int ret = ERROR_SUCCESS; | 1877 | int ret = ERROR_SUCCESS; |
| 1878 | + | ||
| 1879 | + objectTypeIndication = (SrsMp4ObjectType)buf->read_1bytes(); | ||
| 1880 | + | ||
| 1881 | + uint8_t v = buf->read_1bytes(); | ||
| 1882 | + upStream = (v>>1) & 0x01; | ||
| 1883 | + streamType = (SrsMp4StreamType)((v>>2) & 0x3f); | ||
| 1884 | + reserved = v&0x01; | ||
| 1885 | + | ||
| 1886 | + bufferSizeDB = buf->read_3bytes(); | ||
| 1887 | + maxBitrate = buf->read_4bytes(); | ||
| 1888 | + avgBitrate = buf->read_4bytes(); | ||
| 1889 | + | ||
| 1890 | + int left = left_space(buf); | ||
| 1891 | + if (left > 0) { | ||
| 1892 | + decSpecificInfo = new SrsMp4DecoderSpecificInfo(); | ||
| 1893 | + if ((ret = decSpecificInfo->decode(buf)) != ERROR_SUCCESS) { | ||
| 1894 | + return ret; | ||
| 1895 | + } | ||
| 1896 | + } | ||
| 1897 | + | ||
| 1815 | return ret; | 1898 | return ret; |
| 1816 | } | 1899 | } |
| 1817 | 1900 | ||
| 1818 | SrsMp4SLConfigDescriptor::SrsMp4SLConfigDescriptor() | 1901 | SrsMp4SLConfigDescriptor::SrsMp4SLConfigDescriptor() |
| 1819 | { | 1902 | { |
| 1820 | - tag = SRS_MP4_ES_TAG_ES_SLConfigDescrTag; | 1903 | + tag = SrsMp4ESTagESSLConfigDescrTag; |
| 1904 | + predefined = 2; | ||
| 1821 | } | 1905 | } |
| 1822 | 1906 | ||
| 1823 | SrsMp4SLConfigDescriptor::~SrsMp4SLConfigDescriptor() | 1907 | SrsMp4SLConfigDescriptor::~SrsMp4SLConfigDescriptor() |
| 1824 | { | 1908 | { |
| 1825 | } | 1909 | } |
| 1826 | 1910 | ||
| 1827 | -uint32_t SrsMp4SLConfigDescriptor::nb_payload() | 1911 | +int32_t SrsMp4SLConfigDescriptor::nb_payload() |
| 1828 | { | 1912 | { |
| 1829 | - return 0; | 1913 | + return 1; |
| 1830 | } | 1914 | } |
| 1831 | 1915 | ||
| 1832 | int SrsMp4SLConfigDescriptor::encode_payload(SrsBuffer* buf) | 1916 | int SrsMp4SLConfigDescriptor::encode_payload(SrsBuffer* buf) |
| 1833 | { | 1917 | { |
| 1834 | int ret = ERROR_SUCCESS; | 1918 | int ret = ERROR_SUCCESS; |
| 1919 | + | ||
| 1920 | + buf->write_1bytes(predefined); | ||
| 1921 | + | ||
| 1835 | return ret; | 1922 | return ret; |
| 1836 | } | 1923 | } |
| 1837 | 1924 | ||
| 1838 | int SrsMp4SLConfigDescriptor::decode_payload(SrsBuffer* buf) | 1925 | int SrsMp4SLConfigDescriptor::decode_payload(SrsBuffer* buf) |
| 1839 | { | 1926 | { |
| 1840 | int ret = ERROR_SUCCESS; | 1927 | int ret = ERROR_SUCCESS; |
| 1928 | + | ||
| 1929 | + predefined = buf->read_1bytes(); | ||
| 1930 | + | ||
| 1931 | + // TODO: FIXME: To support complete SL Config. | ||
| 1932 | + if (predefined != 0x02) { | ||
| 1933 | + ret = ERROR_MP4_ESDS_SL_Config; | ||
| 1934 | + srs_error("MP4 illegal ESDS SL Config, predefined=%d. ret=%d", predefined, ret); | ||
| 1935 | + return ret; | ||
| 1936 | + } | ||
| 1937 | + | ||
| 1841 | return ret; | 1938 | return ret; |
| 1842 | } | 1939 | } |
| 1843 | 1940 | ||
| 1844 | SrsMp4ES_Descriptor::SrsMp4ES_Descriptor() | 1941 | SrsMp4ES_Descriptor::SrsMp4ES_Descriptor() |
| 1845 | { | 1942 | { |
| 1846 | - tag = SRS_MP4_ES_TAG_ES_DescrTag; | 1943 | + tag = SrsMp4ESTagESDescrTag; |
| 1847 | streamDependenceFlag = URL_Flag = OCRstreamFlag = 0; | 1944 | streamDependenceFlag = URL_Flag = OCRstreamFlag = 0; |
| 1848 | URLlength = 0; | 1945 | URLlength = 0; |
| 1849 | URLstring = NULL; | 1946 | URLstring = NULL; |
| @@ -1854,7 +1951,7 @@ SrsMp4ES_Descriptor::~SrsMp4ES_Descriptor() | @@ -1854,7 +1951,7 @@ SrsMp4ES_Descriptor::~SrsMp4ES_Descriptor() | ||
| 1854 | srs_freepa(URLstring); | 1951 | srs_freepa(URLstring); |
| 1855 | } | 1952 | } |
| 1856 | 1953 | ||
| 1857 | -uint32_t SrsMp4ES_Descriptor::nb_payload() | 1954 | +int32_t SrsMp4ES_Descriptor::nb_payload() |
| 1858 | { | 1955 | { |
| 1859 | int size = 2 +1; | 1956 | int size = 2 +1; |
| 1860 | size += streamDependenceFlag? 2:0; | 1957 | size += streamDependenceFlag? 2:0; |
| @@ -1962,7 +2059,7 @@ int SrsMp4ES_Descriptor::decode_payload(SrsBuffer* buf) | @@ -1962,7 +2059,7 @@ int SrsMp4ES_Descriptor::decode_payload(SrsBuffer* buf) | ||
| 1962 | 2059 | ||
| 1963 | SrsMp4EsdsBox::SrsMp4EsdsBox() | 2060 | SrsMp4EsdsBox::SrsMp4EsdsBox() |
| 1964 | { | 2061 | { |
| 1965 | - type = SRS_MP4_BOX_ESDS; | 2062 | + type = SrsMp4BoxTypeESDS; |
| 1966 | es = new SrsMp4ES_Descriptor(); | 2063 | es = new SrsMp4ES_Descriptor(); |
| 1967 | } | 2064 | } |
| 1968 | 2065 | ||
| @@ -2016,7 +2113,7 @@ int SrsMp4EsdsBox::decode_header(SrsBuffer* buf) | @@ -2016,7 +2113,7 @@ int SrsMp4EsdsBox::decode_header(SrsBuffer* buf) | ||
| 2016 | 2113 | ||
| 2017 | SrsMp4SampleDescriptionBox::SrsMp4SampleDescriptionBox() | 2114 | SrsMp4SampleDescriptionBox::SrsMp4SampleDescriptionBox() |
| 2018 | { | 2115 | { |
| 2019 | - type = SRS_MP4_BOX_STSD; | 2116 | + type = SrsMp4BoxTypeSTSD; |
| 2020 | } | 2117 | } |
| 2021 | 2118 | ||
| 2022 | SrsMp4SampleDescriptionBox::~SrsMp4SampleDescriptionBox() | 2119 | SrsMp4SampleDescriptionBox::~SrsMp4SampleDescriptionBox() |
| @@ -2113,7 +2210,7 @@ SrsMp4SttsEntry::SrsMp4SttsEntry() | @@ -2113,7 +2210,7 @@ SrsMp4SttsEntry::SrsMp4SttsEntry() | ||
| 2113 | 2210 | ||
| 2114 | SrsMp4DecodingTime2SampleBox::SrsMp4DecodingTime2SampleBox() | 2211 | SrsMp4DecodingTime2SampleBox::SrsMp4DecodingTime2SampleBox() |
| 2115 | { | 2212 | { |
| 2116 | - type = SRS_MP4_BOX_STTS; | 2213 | + type = SrsMp4BoxTypeSTTS; |
| 2117 | 2214 | ||
| 2118 | entry_count = 0; | 2215 | entry_count = 0; |
| 2119 | entries = NULL; | 2216 | entries = NULL; |
| @@ -2176,7 +2273,7 @@ SrsMp4CttsEntry::SrsMp4CttsEntry() | @@ -2176,7 +2273,7 @@ SrsMp4CttsEntry::SrsMp4CttsEntry() | ||
| 2176 | 2273 | ||
| 2177 | SrsMp4CompositionTime2SampleBox::SrsMp4CompositionTime2SampleBox() | 2274 | SrsMp4CompositionTime2SampleBox::SrsMp4CompositionTime2SampleBox() |
| 2178 | { | 2275 | { |
| 2179 | - type = SRS_MP4_BOX_CTTS; | 2276 | + type = SrsMp4BoxTypeCTTS; |
| 2180 | 2277 | ||
| 2181 | entry_count = 0; | 2278 | entry_count = 0; |
| 2182 | entries = NULL; | 2279 | entries = NULL; |
| @@ -2241,7 +2338,7 @@ int SrsMp4CompositionTime2SampleBox::decode_header(SrsBuffer* buf) | @@ -2241,7 +2338,7 @@ int SrsMp4CompositionTime2SampleBox::decode_header(SrsBuffer* buf) | ||
| 2241 | 2338 | ||
| 2242 | SrsMp4SyncSampleBox::SrsMp4SyncSampleBox() | 2339 | SrsMp4SyncSampleBox::SrsMp4SyncSampleBox() |
| 2243 | { | 2340 | { |
| 2244 | - type = SRS_MP4_BOX_STSS; | 2341 | + type = SrsMp4BoxTypeSTSS; |
| 2245 | 2342 | ||
| 2246 | entry_count = 0; | 2343 | entry_count = 0; |
| 2247 | sample_numbers = NULL; | 2344 | sample_numbers = NULL; |
| @@ -2302,7 +2399,7 @@ SrsMp4StscEntry::SrsMp4StscEntry() | @@ -2302,7 +2399,7 @@ SrsMp4StscEntry::SrsMp4StscEntry() | ||
| 2302 | 2399 | ||
| 2303 | SrsMp4Sample2ChunkBox::SrsMp4Sample2ChunkBox() | 2400 | SrsMp4Sample2ChunkBox::SrsMp4Sample2ChunkBox() |
| 2304 | { | 2401 | { |
| 2305 | - type = SRS_MP4_BOX_STSC; | 2402 | + type = SrsMp4BoxTypeSTSC; |
| 2306 | 2403 | ||
| 2307 | entry_count = 0; | 2404 | entry_count = 0; |
| 2308 | entries = NULL; | 2405 | entries = NULL; |
| @@ -2361,7 +2458,7 @@ int SrsMp4Sample2ChunkBox::decode_header(SrsBuffer* buf) | @@ -2361,7 +2458,7 @@ int SrsMp4Sample2ChunkBox::decode_header(SrsBuffer* buf) | ||
| 2361 | 2458 | ||
| 2362 | SrsMp4ChunkOffsetBox::SrsMp4ChunkOffsetBox() | 2459 | SrsMp4ChunkOffsetBox::SrsMp4ChunkOffsetBox() |
| 2363 | { | 2460 | { |
| 2364 | - type = SRS_MP4_BOX_STCO; | 2461 | + type = SrsMp4BoxTypeSTCO; |
| 2365 | 2462 | ||
| 2366 | entry_count = 0; | 2463 | entry_count = 0; |
| 2367 | entries = NULL; | 2464 | entries = NULL; |
| @@ -2414,7 +2511,7 @@ int SrsMp4ChunkOffsetBox::decode_header(SrsBuffer* buf) | @@ -2414,7 +2511,7 @@ int SrsMp4ChunkOffsetBox::decode_header(SrsBuffer* buf) | ||
| 2414 | 2511 | ||
| 2415 | SrsMp4ChunkLargeOffsetBox::SrsMp4ChunkLargeOffsetBox() | 2512 | SrsMp4ChunkLargeOffsetBox::SrsMp4ChunkLargeOffsetBox() |
| 2416 | { | 2513 | { |
| 2417 | - type = SRS_MP4_BOX_CO64; | 2514 | + type = SrsMp4BoxTypeCO64; |
| 2418 | 2515 | ||
| 2419 | entry_count = 0; | 2516 | entry_count = 0; |
| 2420 | entries = NULL; | 2517 | entries = NULL; |
| @@ -2467,7 +2564,7 @@ int SrsMp4ChunkLargeOffsetBox::decode_header(SrsBuffer* buf) | @@ -2467,7 +2564,7 @@ int SrsMp4ChunkLargeOffsetBox::decode_header(SrsBuffer* buf) | ||
| 2467 | 2564 | ||
| 2468 | SrsMp4SampleSizeBox::SrsMp4SampleSizeBox() | 2565 | SrsMp4SampleSizeBox::SrsMp4SampleSizeBox() |
| 2469 | { | 2566 | { |
| 2470 | - type = SRS_MP4_BOX_STSZ; | 2567 | + type = SrsMp4BoxTypeSTSZ; |
| 2471 | 2568 | ||
| 2472 | sample_size = sample_count = 0; | 2569 | sample_size = sample_count = 0; |
| 2473 | entry_sizes = NULL; | 2570 | entry_sizes = NULL; |
| @@ -2551,16 +2648,16 @@ int SrsMp4Decoder::initialize(ISrsReader* r) | @@ -2551,16 +2648,16 @@ int SrsMp4Decoder::initialize(ISrsReader* r) | ||
| 2551 | SrsMp4Box* box = NULL; | 2648 | SrsMp4Box* box = NULL; |
| 2552 | SrsAutoFree(SrsMp4Box, box); | 2649 | SrsAutoFree(SrsMp4Box, box); |
| 2553 | 2650 | ||
| 2554 | - if ((ret = load_next_box(&box, SRS_MP4_BOX_FTYP)) != ERROR_SUCCESS) { | 2651 | + if ((ret = load_next_box(&box, SrsMp4BoxTypeFTYP)) != ERROR_SUCCESS) { |
| 2555 | return ret; | 2652 | return ret; |
| 2556 | } | 2653 | } |
| 2557 | SrsMp4FileTypeBox* ftyp = dynamic_cast<SrsMp4FileTypeBox*>(box); | 2654 | SrsMp4FileTypeBox* ftyp = dynamic_cast<SrsMp4FileTypeBox*>(box); |
| 2558 | 2655 | ||
| 2559 | bool legal_brand = false; | 2656 | bool legal_brand = false; |
| 2560 | - static uint32_t legal_brands[] = { | ||
| 2561 | - SRS_MP4_BRAND_ISOM, SRS_MP4_BRAND_ISO2, SRS_MP4_BRAND_AVC1, SRS_MP4_BRAND_MP41 | 2657 | + static SrsMp4BoxBrand legal_brands[] = { |
| 2658 | + SrsMp4BoxBrandISOM, SrsMp4BoxBrandISO2, SrsMp4BoxBrandAVC1, SrsMp4BoxBrandMP41 | ||
| 2562 | }; | 2659 | }; |
| 2563 | - for (int i = 0; i < sizeof(legal_brands)/sizeof(uint32_t); i++) { | 2660 | + for (int i = 0; i < sizeof(legal_brands)/sizeof(SrsMp4BoxBrand); i++) { |
| 2564 | if (ftyp->major_brand == legal_brands[i]) { | 2661 | if (ftyp->major_brand == legal_brands[i]) { |
| 2565 | legal_brand = true; | 2662 | legal_brand = true; |
| 2566 | break; | 2663 | break; |
| @@ -41,6 +41,67 @@ class SrsSimpleStream; | @@ -41,6 +41,67 @@ class SrsSimpleStream; | ||
| 41 | * 4.2 Object Structure | 41 | * 4.2 Object Structure |
| 42 | * ISO_IEC_14496-12-base-format-2012.pdf, page 16 | 42 | * ISO_IEC_14496-12-base-format-2012.pdf, page 16 |
| 43 | */ | 43 | */ |
| 44 | +enum SrsMp4BoxType | ||
| 45 | +{ | ||
| 46 | + SrsMp4BoxTypeForbidden = 0x00, | ||
| 47 | + | ||
| 48 | + SrsMp4BoxTypeUUID = 0x75756964, // 'uuid' | ||
| 49 | + SrsMp4BoxTypeFTYP = 0x66747970, // 'ftyp' | ||
| 50 | + SrsMp4BoxTypeMDAT = 0x6d646174, // 'mdat' | ||
| 51 | + SrsMp4BoxTypeFREE = 0x66726565, // 'free' | ||
| 52 | + SrsMp4BoxTypeSKIP = 0x736b6970, // 'skip' | ||
| 53 | + SrsMp4BoxTypeMOOV = 0x6d6f6f76, // 'moov' | ||
| 54 | + SrsMp4BoxTypeMVHD = 0x6d766864, // 'mvhd' | ||
| 55 | + SrsMp4BoxTypeTRAK = 0x7472616b, // 'trak' | ||
| 56 | + SrsMp4BoxTypeTKHD = 0x746b6864, // 'tkhd' | ||
| 57 | + SrsMp4BoxTypeEDTS = 0x65647473, // 'edts' | ||
| 58 | + SrsMp4BoxTypeELST = 0x656c7374, // 'elst' | ||
| 59 | + SrsMp4BoxTypeMDIA = 0x6d646961, // 'mdia' | ||
| 60 | + SrsMp4BoxTypeMDHD = 0x6d646864, // 'mdhd' | ||
| 61 | + SrsMp4BoxTypeHDLR = 0x68646c72, // 'hdlr' | ||
| 62 | + SrsMp4BoxTypeMINF = 0x6d696e66, // 'minf' | ||
| 63 | + SrsMp4BoxTypeVMHD = 0x766d6864, // 'vmhd' | ||
| 64 | + SrsMp4BoxTypeSMHD = 0x736d6864, // 'smhd' | ||
| 65 | + SrsMp4BoxTypeDINF = 0x64696e66, // 'dinf' | ||
| 66 | + SrsMp4BoxTypeURL = 0x75726c20, // 'url ' | ||
| 67 | + SrsMp4BoxTypeURN = 0x75726e20, // 'urn ' | ||
| 68 | + SrsMp4BoxTypeDREF = 0x64726566, // 'dref' | ||
| 69 | + SrsMp4BoxTypeSTBL = 0x7374626c, // 'stbl' | ||
| 70 | + SrsMp4BoxTypeSTSD = 0x73747364, // 'stsd' | ||
| 71 | + SrsMp4BoxTypeSTTS = 0x73747473, // 'stts' | ||
| 72 | + SrsMp4BoxTypeCTTS = 0x63747473, // 'ctts' | ||
| 73 | + SrsMp4BoxTypeSTSS = 0x73747373, // 'stss' | ||
| 74 | + SrsMp4BoxTypeSTSC = 0x73747363, // 'stsc' | ||
| 75 | + SrsMp4BoxTypeSTCO = 0x7374636f, // 'stco' | ||
| 76 | + SrsMp4BoxTypeCO64 = 0x636f3634, // 'co64' | ||
| 77 | + SrsMp4BoxTypeSTSZ = 0x7374737a, // 'stsz' | ||
| 78 | + SrsMp4BoxTypeSTZ2 = 0x73747a32, // 'stz2' | ||
| 79 | + SrsMp4BoxTypeAVC1 = 0x61766331, // 'avc1' | ||
| 80 | + SrsMp4BoxTypeAVCC = 0x61766343, // 'avcC' | ||
| 81 | + SrsMp4BoxTypeMP4A = 0x6d703461, // 'mp4a' | ||
| 82 | + SrsMp4BoxTypeESDS = 0x65736473, // 'esds' | ||
| 83 | + | ||
| 84 | + SrsMp4BoxTypeVIDE = 0x76696465, // 'vide' | ||
| 85 | + SrsMp4BoxTypeSOUN = 0x736f756e, // 'soun' | ||
| 86 | +}; | ||
| 87 | + | ||
| 88 | +/** | ||
| 89 | + * File format brands | ||
| 90 | + * ISO_IEC_14496-12-base-format-2012.pdf, page 166 | ||
| 91 | + */ | ||
| 92 | +enum SrsMp4BoxBrand | ||
| 93 | +{ | ||
| 94 | + SrsMp4BoxBrandForbidden = 0x00, | ||
| 95 | + SrsMp4BoxBrandISOM = 0x69736f6d, // 'isom' | ||
| 96 | + SrsMp4BoxBrandISO2 = 0x69736f32, // 'iso2' | ||
| 97 | + SrsMp4BoxBrandAVC1 = 0x61766331, // 'avc1' | ||
| 98 | + SrsMp4BoxBrandMP41 = 0x6d703431, // 'mp41' | ||
| 99 | +}; | ||
| 100 | + | ||
| 101 | +/** | ||
| 102 | + * 4.2 Object Structure | ||
| 103 | + * ISO_IEC_14496-12-base-format-2012.pdf, page 16 | ||
| 104 | + */ | ||
| 44 | class SrsMp4Box : public ISrsCodec | 105 | class SrsMp4Box : public ISrsCodec |
| 45 | { | 106 | { |
| 46 | private: | 107 | private: |
| @@ -56,7 +117,7 @@ public: | @@ -56,7 +117,7 @@ public: | ||
| 56 | // identifies the box type; standard boxes use a compact type, which is normally four printable | 117 | // identifies the box type; standard boxes use a compact type, which is normally four printable |
| 57 | // characters, to permit ease of identification, and is shown so in the boxes below. User extensions use | 118 | // characters, to permit ease of identification, and is shown so in the boxes below. User extensions use |
| 58 | // an extended type; in this case, the type field is set to ‘uuid’. | 119 | // an extended type; in this case, the type field is set to ‘uuid’. |
| 59 | - uint32_t type; | 120 | + SrsMp4BoxType type; |
| 60 | // For box 'uuid'. | 121 | // For box 'uuid'. |
| 61 | uint8_t* usertype; | 122 | uint8_t* usertype; |
| 62 | private: | 123 | private: |
| @@ -133,13 +194,13 @@ class SrsMp4FileTypeBox : public SrsMp4Box | @@ -133,13 +194,13 @@ class SrsMp4FileTypeBox : public SrsMp4Box | ||
| 133 | { | 194 | { |
| 134 | public: | 195 | public: |
| 135 | // a brand identifier | 196 | // a brand identifier |
| 136 | - uint32_t major_brand; | 197 | + SrsMp4BoxBrand major_brand; |
| 137 | // an informative integer for the minor version of the major brand | 198 | // an informative integer for the minor version of the major brand |
| 138 | uint32_t minor_version; | 199 | uint32_t minor_version; |
| 139 | private: | 200 | private: |
| 140 | // a list, to the end of the box, of brands | 201 | // a list, to the end of the box, of brands |
| 141 | int nb_compatible_brands; | 202 | int nb_compatible_brands; |
| 142 | - uint32_t* compatible_brands; | 203 | + SrsMp4BoxBrand* compatible_brands; |
| 143 | public: | 204 | public: |
| 144 | SrsMp4FileTypeBox(); | 205 | SrsMp4FileTypeBox(); |
| 145 | virtual ~SrsMp4FileTypeBox(); | 206 | virtual ~SrsMp4FileTypeBox(); |
| @@ -726,15 +787,15 @@ protected: | @@ -726,15 +787,15 @@ protected: | ||
| 726 | 787 | ||
| 727 | // Table 1 — List of Class Tags for Descriptors | 788 | // Table 1 — List of Class Tags for Descriptors |
| 728 | // ISO_IEC_14496-1-System-2010.pdf, page 31 | 789 | // ISO_IEC_14496-1-System-2010.pdf, page 31 |
| 729 | -enum SRS_MP4_ES_TAG_ES { | ||
| 730 | - SRS_MP4_ES_TAG_ES_forbidden = 0x00, | ||
| 731 | - SRS_MP4_ES_TAG_ES_ObjectDescrTag = 0x01, | ||
| 732 | - SRS_MP4_ES_TAG_ES_InitialObjectDescrTag = 0x02, | ||
| 733 | - SRS_MP4_ES_TAG_ES_DescrTag = 0x03, | ||
| 734 | - SRS_MP4_ES_TAG_ES_DecoderConfigDescrTag = 0x04, | ||
| 735 | - SRS_MP4_ES_TAG_ES_DecSpecificInfoTag = 0x05, | ||
| 736 | - SRS_MP4_ES_TAG_ES_SLConfigDescrTag = 0x06, | ||
| 737 | - SRS_MP4_ES_TAG_ES_ExtSLConfigDescrTag = 0x064, | 790 | +enum SrsMp4ESTagEs { |
| 791 | + SrsMp4ESTagESforbidden = 0x00, | ||
| 792 | + SrsMp4ESTagESObjectDescrTag = 0x01, | ||
| 793 | + SrsMp4ESTagESInitialObjectDescrTag = 0x02, | ||
| 794 | + SrsMp4ESTagESDescrTag = 0x03, | ||
| 795 | + SrsMp4ESTagESDecoderConfigDescrTag = 0x04, | ||
| 796 | + SrsMp4ESTagESDecSpecificInfoTag = 0x05, | ||
| 797 | + SrsMp4ESTagESSLConfigDescrTag = 0x06, | ||
| 798 | + SrsMp4ESTagESExtSLConfigDescrTag = 0x064, | ||
| 738 | }; | 799 | }; |
| 739 | 800 | ||
| 740 | /** | 801 | /** |
| @@ -747,21 +808,66 @@ public: | @@ -747,21 +808,66 @@ public: | ||
| 747 | // The values of the class tags are | 808 | // The values of the class tags are |
| 748 | // defined in Table 2. As an expandable class the size of each class instance in bytes is encoded and accessible | 809 | // defined in Table 2. As an expandable class the size of each class instance in bytes is encoded and accessible |
| 749 | // through the instance variable sizeOfInstance (see 8.3.3). | 810 | // through the instance variable sizeOfInstance (see 8.3.3). |
| 750 | - SRS_MP4_ES_TAG_ES tag; // bit(8) | 811 | + SrsMp4ESTagEs tag; // bit(8) |
| 812 | + // The decoded or encoded variant length. | ||
| 813 | + int32_t vlen; // bit(28) | ||
| 814 | +private: | ||
| 815 | + // The position at buffer to start demux the box. | ||
| 816 | + int start_pos; | ||
| 751 | public: | 817 | public: |
| 752 | SrsMp4BaseDescriptor(); | 818 | SrsMp4BaseDescriptor(); |
| 753 | virtual ~SrsMp4BaseDescriptor(); | 819 | virtual ~SrsMp4BaseDescriptor(); |
| 820 | +public: | ||
| 821 | + // Get the left space of box, for decoder. | ||
| 822 | + virtual int left_space(SrsBuffer* buf); | ||
| 754 | // Interface ISrsCodec | 823 | // Interface ISrsCodec |
| 755 | public: | 824 | public: |
| 756 | virtual int nb_bytes(); | 825 | virtual int nb_bytes(); |
| 757 | virtual int encode(SrsBuffer* buf); | 826 | virtual int encode(SrsBuffer* buf); |
| 758 | virtual int decode(SrsBuffer* buf); | 827 | virtual int decode(SrsBuffer* buf); |
| 759 | protected: | 828 | protected: |
| 760 | - virtual uint32_t nb_payload() = 0; | 829 | + virtual int32_t nb_payload() = 0; |
| 761 | virtual int encode_payload(SrsBuffer* buf) = 0; | 830 | virtual int encode_payload(SrsBuffer* buf) = 0; |
| 762 | virtual int decode_payload(SrsBuffer* buf) = 0; | 831 | virtual int decode_payload(SrsBuffer* buf) = 0; |
| 763 | }; | 832 | }; |
| 764 | 833 | ||
| 834 | +// Table 5 — objectTypeIndication Values | ||
| 835 | +// ISO_IEC_14496-1-System-2010.pdf, page 49 | ||
| 836 | +enum SrsMp4ObjectType | ||
| 837 | +{ | ||
| 838 | + SrsMp4ObjectTypeForbidden = 0x00, | ||
| 839 | + // Audio ISO/IEC 14496-3 | ||
| 840 | + SrsMp4ObjectTypeAac = 0x40, | ||
| 841 | +}; | ||
| 842 | + | ||
| 843 | +// Table 6 — streamType Values | ||
| 844 | +// ISO_IEC_14496-1-System-2010.pdf, page 51 | ||
| 845 | +enum SrsMp4StreamType | ||
| 846 | +{ | ||
| 847 | + SrsMp4StreamTypeForbidden = 0x00, | ||
| 848 | + SrsMp4StreamTypeAudioStream = 0x05, | ||
| 849 | +}; | ||
| 850 | + | ||
| 851 | +/** | ||
| 852 | + * 7.2.6.7 DecoderSpecificInfo | ||
| 853 | + * ISO_IEC_14496-1-System-2010.pdf, page 51 | ||
| 854 | + */ | ||
| 855 | +class SrsMp4DecoderSpecificInfo : public SrsMp4BaseDescriptor | ||
| 856 | +{ | ||
| 857 | +public: | ||
| 858 | + // AAC Audio Specific Config. | ||
| 859 | + // 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33. | ||
| 860 | + int nb_asc; | ||
| 861 | + uint8_t* asc; | ||
| 862 | +public: | ||
| 863 | + SrsMp4DecoderSpecificInfo(); | ||
| 864 | + virtual ~SrsMp4DecoderSpecificInfo(); | ||
| 865 | +protected: | ||
| 866 | + virtual int32_t nb_payload(); | ||
| 867 | + virtual int encode_payload(SrsBuffer* buf); | ||
| 868 | + virtual int decode_payload(SrsBuffer* buf); | ||
| 869 | +}; | ||
| 870 | + | ||
| 765 | /** | 871 | /** |
| 766 | * 7.2.6.6 DecoderConfigDescriptor | 872 | * 7.2.6.6 DecoderConfigDescriptor |
| 767 | * ISO_IEC_14496-1-System-2010.pdf, page 48 | 873 | * ISO_IEC_14496-1-System-2010.pdf, page 48 |
| @@ -769,18 +875,21 @@ protected: | @@ -769,18 +875,21 @@ protected: | ||
| 769 | class SrsMp4DecoderConfigDescriptor : public SrsMp4BaseDescriptor | 875 | class SrsMp4DecoderConfigDescriptor : public SrsMp4BaseDescriptor |
| 770 | { | 876 | { |
| 771 | public: | 877 | public: |
| 772 | - uint8_t objectTypeIndication; | ||
| 773 | - uint8_t streamType; // bit(6) | 878 | + // an indication of the object or scene description type that needs to be supported |
| 879 | + // by the decoder for this elementary stream as per Table 5. | ||
| 880 | + SrsMp4ObjectType objectTypeIndication; | ||
| 881 | + SrsMp4StreamType streamType; // bit(6) | ||
| 774 | uint8_t upStream; // bit(1) | 882 | uint8_t upStream; // bit(1) |
| 775 | uint8_t reserved; // bit(1) | 883 | uint8_t reserved; // bit(1) |
| 776 | uint32_t bufferSizeDB; // bit(24) | 884 | uint32_t bufferSizeDB; // bit(24) |
| 777 | uint32_t maxBitrate; | 885 | uint32_t maxBitrate; |
| 778 | uint32_t avgBitrate; | 886 | uint32_t avgBitrate; |
| 887 | + SrsMp4DecoderSpecificInfo* decSpecificInfo; // optional. | ||
| 779 | public: | 888 | public: |
| 780 | SrsMp4DecoderConfigDescriptor(); | 889 | SrsMp4DecoderConfigDescriptor(); |
| 781 | virtual ~SrsMp4DecoderConfigDescriptor(); | 890 | virtual ~SrsMp4DecoderConfigDescriptor(); |
| 782 | protected: | 891 | protected: |
| 783 | - virtual uint32_t nb_payload(); | 892 | + virtual int32_t nb_payload(); |
| 784 | virtual int encode_payload(SrsBuffer* buf); | 893 | virtual int encode_payload(SrsBuffer* buf); |
| 785 | virtual int decode_payload(SrsBuffer* buf); | 894 | virtual int decode_payload(SrsBuffer* buf); |
| 786 | }; | 895 | }; |
| @@ -793,37 +902,11 @@ class SrsMp4SLConfigDescriptor : public SrsMp4BaseDescriptor | @@ -793,37 +902,11 @@ class SrsMp4SLConfigDescriptor : public SrsMp4BaseDescriptor | ||
| 793 | { | 902 | { |
| 794 | public: | 903 | public: |
| 795 | uint8_t predefined; | 904 | uint8_t predefined; |
| 796 | - // if (predefined==0) | ||
| 797 | - uint8_t useAccessUnitStartFlag; // bit(1) | ||
| 798 | - uint8_t useAccessUnitEndFlag; // bit(1) | ||
| 799 | - uint8_t useRandomAccessPointFlag; // bit(1) | ||
| 800 | - uint8_t hasRandomAccessUnitsOnlyFlag; // bit(1) | ||
| 801 | - uint8_t usePaddingFlag; // bit(1) | ||
| 802 | - uint8_t useTimeStampsFlag; // bit(1) | ||
| 803 | - uint8_t useIdleFlag; // bit(1) | ||
| 804 | - uint8_t durationFlag; // bit(1) | ||
| 805 | - uint32_t timeStampResolution; | ||
| 806 | - uint32_t OCRResolution; | ||
| 807 | - uint8_t timeStampLength; // must be ≤ 64 | ||
| 808 | - uint8_t OCRLength; // must be ≤ 64 | ||
| 809 | - uint8_t AU_Length; // must be ≤ 32 | ||
| 810 | - uint8_t instantBitrateLength; | ||
| 811 | - uint8_t degradationPriorityLength; // bit(4) | ||
| 812 | - uint8_t AU_seqNumLength; // bit(5) // must be ≤ 16 | ||
| 813 | - uint8_t packetSeqNumLength; // bit(5) // must be ≤ 16 | ||
| 814 | - uint8_t reserved; // bit(2) // 0b11 | ||
| 815 | - // if (durationFlag) | ||
| 816 | - uint32_t timeScale; | ||
| 817 | - uint16_t accessUnitDuration; | ||
| 818 | - uint16_t compositionUnitDuration; | ||
| 819 | - // if (!useTimeStampsFlag) | ||
| 820 | - uint64_t startDecodingTimeStamp; // bit(timeStampLength) | ||
| 821 | - uint64_t startCompositionTimeStamp; // bit(timeStampLength) | ||
| 822 | public: | 905 | public: |
| 823 | SrsMp4SLConfigDescriptor(); | 906 | SrsMp4SLConfigDescriptor(); |
| 824 | virtual ~SrsMp4SLConfigDescriptor(); | 907 | virtual ~SrsMp4SLConfigDescriptor(); |
| 825 | protected: | 908 | protected: |
| 826 | - virtual uint32_t nb_payload(); | 909 | + virtual int32_t nb_payload(); |
| 827 | virtual int encode_payload(SrsBuffer* buf); | 910 | virtual int encode_payload(SrsBuffer* buf); |
| 828 | virtual int decode_payload(SrsBuffer* buf); | 911 | virtual int decode_payload(SrsBuffer* buf); |
| 829 | }; | 912 | }; |
| @@ -853,7 +936,7 @@ public: | @@ -853,7 +936,7 @@ public: | ||
| 853 | SrsMp4ES_Descriptor(); | 936 | SrsMp4ES_Descriptor(); |
| 854 | virtual ~SrsMp4ES_Descriptor(); | 937 | virtual ~SrsMp4ES_Descriptor(); |
| 855 | protected: | 938 | protected: |
| 856 | - virtual uint32_t nb_payload(); | 939 | + virtual int32_t nb_payload(); |
| 857 | virtual int encode_payload(SrsBuffer* buf); | 940 | virtual int encode_payload(SrsBuffer* buf); |
| 858 | virtual int decode_payload(SrsBuffer* buf); | 941 | virtual int decode_payload(SrsBuffer* buf); |
| 859 | }; | 942 | }; |
-
请 注册 或 登录 后发表评论