| #include <vector> |
| 6 | #include <string> |
| 7 | #include <map> |
| 8 | #include <stdint.h> |
| 9 |
| 10 | #include "AVIOContextImpl.h" |
| 11 | #include "AudioStreamingPartPersistentDecoder.h" |
| 12 |
| 13 | namespace tgcalls { |
| 14 |
| 15 | class AudioStreamingPartInternal { |
| 16 | public: |
| 17 | struct ReadPcmResult { |
| 18 | int numSamples = 0; |
| 19 | int numChannels = 0; |
| 20 | }; |
| 21 |
| 22 | struct ChannelUpdate { |
| 23 | int frameIndex = 0; |
| 24 | int id = 0; |
| 25 | uint32_t ssrc = 0; |
| 26 | }; |
| 27 |
| 28 | public: |
| 29 | AudioStreamingPartInternal(std::vector<uint8_t> &&fileData, std::string const &container); |
| 30 | ~AudioStreamingPartInternal(); |
| 31 |
| 32 | ReadPcmResult readPcm(AudioStreamingPartPersistentDecoder &persistentDecoder, std::vector<int16_t> &outPcm); |
| 33 | int getDurationInMilliseconds() const; |
| 34 | std::vector<ChannelUpdate> const &getChannelUpdates() const; |
| 35 | std::map<std::string, int32_t> getEndpointMapping() const; |
| 36 |
| 37 | private: |
| 38 | void fillPcmBuffer(AudioStreamingPartPersistentDecoder &persistentDecoder); |
| 39 |
| 40 | private: |
| 41 | AVIOContextImpl _avIoContext; |
| 42 |
| 43 | AVFormatContext *_inputFormatContext = nullptr; |
| 44 | AVPacket _packet; |
| 45 | AVFrame *_frame = nullptr; |
| 46 | AVCodecParameters *_audioCodecParameters = nullptr; |
| 47 |
| 48 | bool _didReadToEnd = false; |
| 49 |
| 50 | int _durationInMilliseconds = 0; |
| 51 | int _streamId = -1; |
| 52 | int _channelCount = 0; |
| 53 |
| 54 | std::vector<ChannelUpdate> _channelUpdates; |
| 55 | std::map<std::string, int32_t> _endpointMapping; |
| 56 |
| 57 | std::vector<int16_t> _pcmBuffer; |
| 58 | int _pcmBufferSampleOffset = 0; |
| 59 | int _pcmBufferSampleSize = 0; |
| 60 | int _readSampleCount = 0; |
| 61 | }; |
| 62 |
| 63 | } |
| 64 |
| 65 | #endif |
| 66 |