kodi
ICodec.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "cores/AudioEngine/Utils/AEAudioFormat.h"
12 #include "filesystem/File.h"
13 #include "music/tags/MusicInfoTag.h"
14 
15 #include <string>
16 
17 #define READ_EOF -1
18 #define READ_SUCCESS 0
19 #define READ_ERROR 1
20 
21 class CFileItem;
22 
23 class ICodec
24 {
25 public:
26  ICodec()
27  {
28  m_TotalTime = 0;
29  m_bitRate = 0;
30  m_bitsPerSample = 0;
31  m_bitsPerCodedSample = 0;
32  };
33  virtual ~ICodec() = default;
34 
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
37  // APE codecs.
38 
39  // Init(filename)
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;
45 
46  virtual bool CanSeek() {return true;}
47 
48  // Seek()
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;
53 
54  // ReadPCM()
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;
59 
60  virtual int ReadRaw(uint8_t **pBuffer, int *bufferSize) { return READ_ERROR; }
61 
62  // CanInit()
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;
66 
67  // set the total time - useful when info comes from a preset tag
68  virtual void SetTotalTime(int64_t totaltime) {}
69 
70  virtual bool IsCaching() const {return false;}
71  virtual int GetCacheLevel() const {return -1;}
72 
73  int64_t m_TotalTime; // time in ms
74  int m_bitRate;
75  int m_bitsPerSample;
76  int m_bitsPerCodedSample;
77  std::string m_CodecName;
79  XFILE::CFile m_file;
80  AEAudioFormat m_format;
81 };
82 
Definition: File.h:37
The audio format structure that fully defines a stream&#39;s audio information.
Definition: AEAudioFormat.h:19
Definition: ICodec.h:23
Definition: MusicInfoTag.h:27
Represents a file on a share.
Definition: FileItem.h:102