1 /***************************************************************************
2     \file ADM_audioAccessfileAACADTS
3     \brief read audio from a file, AAC inside ADTS
4     \author mean (c) 2012 fixounet@free.fr
5  ***************************************************************************/
6 
7 /***************************************************************************
8  *                                                                         *
9  *   This program is free software; you can redistribute it and/or modify  *
10  *   it under the terms of the GNU General Public License as published by  *
11  *   the Free Software Foundation; either version 2 of the License, or     *
12  *   (at your option) any later version.                                   *
13  *                                                                         *
14  ***************************************************************************/
15 #pragma once
16 #include "ADM_coreAudio6_export.h"
17 #include "ADM_audioStream.h"
18 #include "vector"
19 #include "ADM_audioClock.h"
20 #include "ADM_aacadts.h"
21 #include <vector>
22 
23 /**
24         \fn      ADM_audioAccessFile
25         \brief   Input is a plain file
26 */
27 
28 class aacAdtsSeek
29 {
30 public:
31     uint64_t position;
32     uint64_t dts;
33 };
34 
35 class ADM_COREAUDIO6_EXPORT ADM_audioAccessFileAACADTS  : public ADM_audioAccess
36 {
37 protected:
38                 FILE            *_fd;
39                 int             _offset;
40                 uint64_t        payloadSize;
41                 uint64_t        durationUs;
42                 bool            inited;
43                 audioClock      *clock;
44                 ADM_adts2aac    *aac;
45                 bool            refill(void);
46                 WAVHeader       headerInfo;
47                  std::vector<aacAdtsSeek>seekPoints;
48 
49 protected:
50                 bool            init(void);
51 
52 public:
53                                   ADM_audioAccessFileAACADTS(const char *fileName,int offset);
54                 virtual           ~ADM_audioAccessFileAACADTS() ;
55 
getHeaderInfo()56             const WAVHeader       &getHeaderInfo() {return headerInfo;};
57 
58                 virtual bool        getPacket(uint8_t *buffer, uint32_t *size, uint32_t maxSize,
59                             uint64_t *dts);
60                                     /// Go to a given time
61                 virtual bool      goToTime(uint64_t timeUs);
62 
63                 // stubs
64                                     /// Hint, the stream is pure CBR (AC3,MP2,MP3)
isCBR(void)65                 virtual bool      isCBR(void) { return false;}
66                                     /// Return true if the demuxer can seek in time
canSeekTime(void)67                 virtual bool      canSeekTime(void) {return true;};
68                                     /// Return true if the demuxer can seek by offser
canSeekOffset(void)69                 virtual bool      canSeekOffset(void) {return false;};
70                                     /// Return true if we can have the audio duration
canGetDuration(void)71                 virtual bool      canGetDuration(void) {return true;};
72                                     /// Returns audio duration in us
getDurationInUs(void)73                 virtual uint64_t  getDurationInUs(void) {return durationUs;}
74 
75                                     /// Grab extra data
getExtraData(uint32_t * l,uint8_t ** d)76                 virtual bool      getExtraData(uint32_t *l, uint8_t **d)
77                                     {
78                                             *l=extraDataLen;
79                                             *d=extraData;
80                                             return true;
81                                     };
82                                     /// Returns length in bytes of the audio stream
getLength(void)83                 virtual uint32_t  getLength(void) {return payloadSize;};
84 
85                                     /// Set position in bytes
setPos(uint64_t pos)86                 virtual bool      setPos(uint64_t pos) { ADM_assert(0);return true;};
87                                     /// Get position in bytes
getPos()88                 virtual uint64_t  getPos() { ADM_assert(0);return true;};
89 
90 
91 };
92 
93 // EOF
94 
95