基于qt,msvc2017-64bits,ffmpeg.opengl的播放器
chenshijun
2020-12-03 9e8804424408db79fcdb229a016ac87952e4e0f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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;
}