#include "csrw.h" #include "minivideo/bitstream.h" #include "minivideo/minivideo_mediafile.h" #include "struct.h" int csrw_fileParse(MediaFile_t* media, DataCallback* dct) { int retcode = SUCCESS; // Init bitstream to parse container infos Bitstream_t* bitstr = init_bitstream(media); uint32_t start_code = 0; uint32_t length = 0; if (bitstr != NULL) { skip_bits(bitstr, 0x10 * 8); while (bitstream_get_absolute_byte_offset(bitstr) < media->file_size - 4) { if (dct && dct->is_quit()) { break; } start_code = read_bits(bitstr, 32); read_chunk(bitstr, (uint8_t*)&length, sizeof(uint32_t)); if (start_code == 0x48584649) { break; } if (start_code == 0x48584146) { if (dct) { dct->open_codec(AUDIO_G711_A, AV_AUDIO); } skip_bits(bitstr, 0xc * 8); length -= 4; uint8_t* chunk = (uint8_t*)malloc(length); read_chunk(bitstr, chunk, length); if (dct) { packet_t* pkt = (packet_t*)malloc(sizeof(packet_t)); pkt->data = chunk; pkt->length = length; pkt->pts = -1; pkt->dts = -1; pkt->type = AV_AUDIO; dct->push_packet(pkt, AV_AUDIO); } } else if (start_code == 0x48585646) { if (dct) { dct->open_codec(VIDEO_H264, AV_VIDEO); } skip_bits(bitstr, 0x8 * 8); uint8_t* chunk = (uint8_t*)malloc(length); read_chunk(bitstr, chunk, length); if (dct) { packet_t* pkt = (packet_t*)malloc(sizeof(packet_t)); pkt->data = chunk; pkt->length = length; pkt->pts = -1; pkt->dts = -1; pkt->type = AV_VIDEO; dct->push_packet(pkt, AV_VIDEO); } } } } free_bitstream(&bitstr); if (dct) dct->push_finish(); printf("demuxer over!!!"); return retcode; }