2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
11 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
12 #include "filesystem/File.h"
13 #include "music/tags/MusicInfoTag.h"
18 #define READ_SUCCESS 0
31 m_bitsPerCodedSample
= 0;
33 virtual ~ICodec() = default;
35 // Virtual functions that all codecs should implement. Note that these may need
36 // enhancing and or refactoring at a later date. It works currently well for MP3 and
40 // This routine should handle any initialization necessary. At a minimum it needs to:
41 // 1. Load any dlls and make sure any buffers etc. are allocated.
42 // 2. Load the file (or at least attempt to load it)
43 // 3. Fill in the m_TotalTime, m_SampleRate, m_BitsPerSample and m_Channels parameters.
44 virtual bool Init(const CFileItem
&file
, unsigned int filecache
)=0;
46 virtual bool CanSeek() {return true;}
49 // Should seek to the appropriate time (in ms) in the file, and return the
50 // time to which we managed to seek (in the case where seeking is problematic)
51 // This is used in FFwd/Rewd so can be called very often.
52 virtual bool Seek(int64_t iSeekTime
)=0;
55 // Decodes audio into pBuffer up to size bytes. The actual amount of returned data
56 // is given in actualsize. Returns READ_SUCCESS on success. Returns READ_EOF when
57 // the data has been exhausted, and READ_ERROR on error.
58 virtual int ReadPCM(uint8_t* pBuffer
, size_t size
, size_t* actualsize
) = 0;
60 virtual int ReadRaw(uint8_t **pBuffer
, int *bufferSize
) { return READ_ERROR
; }
63 // Should return true if the codec can be initialized
64 // eg. check if a dll needed for the codec exists
65 virtual bool CanInit()=0;
67 // set the total time - useful when info comes from a preset tag
68 virtual void SetTotalTime(int64_t totaltime
) {}
70 virtual bool IsCaching() const {return false;}
71 virtual int GetCacheLevel() const {return -1;}
73 int64_t m_TotalTime
; // time in ms
76 int m_bitsPerCodedSample
;
77 std::string m_CodecName
;
78 MUSIC_INFO::CMusicInfoTag m_tag
;
80 AEAudioFormat m_format
;