1 /**
2 \file ADM_audioStreamDCA
3 \brief DCA Handling class
4
5 */
6 #include "ADM_default.h"
7 #include "ADM_audioStreamDCA.h"
8 #include "ADM_dcainfo.h"
9
10 /**
11 \fn ADM_audioStreamDCA
12 \brief constructor
13 */
ADM_audioStreamDCA(WAVHeader * header,ADM_audioAccess * access)14 ADM_audioStreamDCA::ADM_audioStreamDCA(WAVHeader *header,ADM_audioAccess *access) : ADM_audioStreamBuffered(header,access)
15 {
16 if(access->canGetDuration()==false)
17 {
18 // We can compute the duration from the length
19 double size=access->getLength();
20 size/=header->byterate; // Result is in second
21 size*=1000;
22 size*=1000; // s->us
23 durationInUs=(uint64_t)size;
24 }
25 }
26
27 /**
28 \fn ADM_audioStream
29 \brief destructor
30 */
~ADM_audioStreamDCA()31 ADM_audioStreamDCA::~ADM_audioStreamDCA()
32 {
33
34 }
35 /**
36 \fn goToTime
37 \brief goToTime
38 */
goToTime(uint64_t nbUs)39 bool ADM_audioStreamDCA::goToTime(uint64_t nbUs)
40 {
41 if(access->canSeekTime()==true)
42 {
43 if( access->goToTime(nbUs)==true)
44 {
45 setDts(nbUs);
46 limit=start=0;
47 refill();
48 return 1;
49 }
50 return 1;
51 }
52 // If CBR we can use the default way
53 return ADM_audioStreamBuffered::goToTime(nbUs);
54
55 }
56 /**
57 \fn getPacket
58 */
getPacket(uint8_t * obuffer,uint32_t * osize,uint32_t sizeMax,uint32_t * nbSample,uint64_t * dts)59 uint8_t ADM_audioStreamDCA::getPacket(uint8_t *obuffer,uint32_t *osize, uint32_t sizeMax,uint32_t *nbSample,uint64_t *dts)
60 {
61 #define ADM_LOOK_AHEAD DTS_HEADER_SIZE // Need 10 bytes...
62 uint8_t data[ADM_LOOK_AHEAD];
63 uint32_t offset;
64 ADM_DCA_INFO info;
65 while(1)
66 {
67 // Do we have sync ?
68 if(needBytes(ADM_LOOK_AHEAD)==false)
69 {
70 ADM_warning("DCA: Not sync found in buffer\n");
71 return false;
72 }
73
74 // Peek
75 peek(ADM_LOOK_AHEAD,data);
76 // Search start seq
77 if(buffer[start]!=0x7F || buffer[start+1]!=0xFE)
78 {
79 read8();
80 continue;
81 }
82 if(buffer[start+2]!=0x80 || buffer[start+3]!=0x1)
83 {
84 read8();
85 read8();
86 continue;
87 }
88
89 if(false== ADM_DCAGetInfo(buffer.at(start), limit-start,&info,&offset))
90 {
91 read8();
92 read8();
93 read8();
94 read8();
95 continue;
96 }
97 ADM_assert(info.frameSizeInBytes<=sizeMax);
98 if(needBytes(info.frameSizeInBytes)==false)
99 {
100 ADM_warning("DCA: Not enough data\n");
101 return false;
102 }
103 *osize=info.frameSizeInBytes;
104 read(*osize,obuffer);
105 *nbSample=info.samples;
106 *dts=lastDts;
107 advanceDtsBySample(*nbSample);
108 return 1;
109
110 }
111 }
112
113 // EOF
114