svc_mediaconverter.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. #ifndef _SVC_MEDIACONVERTER_H
  2. #define _SVC_MEDIACONVERTER_H
  3. #include <bfc/dispatch.h>
  4. #include <api/core/chunklist.h>
  5. #include <api/core/mediainfo.h>
  6. #include <api/syscb/callbacks/corecbi.h>
  7. #include <api/service/services.h>
  8. // do NOT derive from these ones
  9. class NOVTABLE svc_mediaConverter : public Dispatchable {
  10. public:
  11. static FOURCC getServiceType() { return WaSvc::MEDIACONVERTER; }
  12. // test if the converter can handle that stream, filename or chunktype:
  13. // if your converter can accept streams depending on the data stream you should
  14. // test the file thru the reader interface (like to test if the file header is ok)
  15. // if your converter can accept files thru a test on the filename string, you should
  16. // test the name string (like tone://... or *.wav)
  17. // if your converter can accept depending on the chunktype, you should test the chunktype
  18. // (like MP3, PCM, etc...)
  19. // returns 1 if ok
  20. int canConvertFrom(svc_fileReader *reader, const char *name, const char *chunktype) { return _call(CANCONVERTFROM,0,reader,name,chunktype); }
  21. // returns the chunk type that the converter will convert to
  22. // (PCM, MP3, etc...)
  23. const char *getConverterTo() { return _call(GETCONVERTERTO,""); }
  24. // override this one if your converter can decode depending on a "Content-Type:" HTTP header
  25. int canSupportContentType(const char *contenttype) { return _call(CANSUPPORTCONTENTTYPE,0,contenttype); }
  26. // fills up the infos class
  27. int getInfos(MediaInfo *infos) { return _call(GETINFOS,0,infos); }
  28. // writes back the infos on the file.
  29. // note: the reader you get in the infos class has the filename opened in read/write mode
  30. // return 1 if update succeeded, 0 if error
  31. int setInfos(MediaInfo *infos) { return _call(SETINFOS,0,infos); }
  32. // returns the id of the xml group the media info editor will use for displaying/editing infos
  33. const char *getInfosXmlGroup() { return _call(GETINFOSXMLGROUP,(const char *)NULL); }
  34. // process current file data
  35. // returns 1 if ok, 0 when file/stream has ended
  36. int processData(MediaInfo *infos, ChunkList *chunk_list, bool *killswitch) { return _call(PROCESSDATA,0,infos,chunk_list,killswitch); }
  37. // returns the current position in ms
  38. // usually the position is automatically calculated with the amount of PCM data converters send back to the core
  39. // so you don't have to override this function. however, if you want to force the position, return a value other than -1
  40. int getPosition(void) { return _call(GETPOSITION,-1); }
  41. // returns the latency of the converter in ms
  42. int getLatency(void) { return _call(GETLATENCY,0); }
  43. // sort function to be able to specify where you want your converter placed in the converter list
  44. // (like if you want to be before or after the crossfader for example, override this function)
  45. // return -1 to be placed before "otherconverter", 1 to be placed after "otherconverter", otherwise 0
  46. int sortPlacement(const char *otherconverter) { return _call(SORTPLACEMENT,0,otherconverter); }
  47. // return 1 if you want this converter to be selectable as output in prefs->audio
  48. int isSelectableOutput(void) { return _call(ISSELECTABLEOUTPUT,0); }
  49. // message received by sendConvertersMsg() in the core
  50. int onCoreUserMsg(const char *msg, const char *value) { return _call(ONCOREUSERMSG,0,msg,value); }
  51. // internally used by wasabi
  52. CoreCallback *getCoreCallback(void) { return _call(GETCORECALLBACK,(CoreCallback *)0); }
  53. void setCoreToken(CoreToken t) { _voidcall(SETCORETOKEN,t); }
  54. enum {
  55. CANCONVERTFROM=10,
  56. GETCONVERTERTO=20,
  57. GETINFOS=30,
  58. PROCESSDATA=40,
  59. GETPOSITION=50,
  60. GETLATENCY=60,
  61. GETCORECALLBACK=70,
  62. SORTPLACEMENT=80,
  63. CANSUPPORTCONTENTTYPE=90,
  64. SETCORETOKEN=100,
  65. SETINFOS=110,
  66. GETINFOSXMLGROUP=120,
  67. ISSELECTABLEOUTPUT=130,
  68. ONCOREUSERMSG=140,
  69. };
  70. };
  71. class NOVTABLE svc_mediaConverterNI : public svc_mediaConverter {
  72. public:
  73. virtual int canConvertFrom(svc_fileReader *reader, const char *name, const char *chunktype)=0;
  74. virtual const char *getConverterTo()=0;
  75. virtual int canSupportContentType(const char *contenttype) { return 0; }
  76. virtual int getInfos(MediaInfo *infos)=0;
  77. virtual int setInfos(MediaInfo *infos)=0;
  78. virtual const char *getInfosXmlGroup()=0;
  79. virtual int processData(MediaInfo *infos, ChunkList *chunk_list, bool *killswitch)=0;
  80. virtual int getPosition(void) { return -1; }
  81. virtual int getLatency(void) { return 0; }
  82. virtual int sortPlacement(const char *otherconverter) { return 0; }
  83. virtual int isSelectableOutput(void) { return 0; }
  84. virtual int onCoreUserMsg(const char *msg, const char *value) { return 0; }
  85. virtual CoreCallback *getCoreCallback(void)=0;
  86. virtual void setCoreToken(CoreToken t)=0;
  87. protected:
  88. RECVS_DISPATCH;
  89. };
  90. // derive from this one
  91. class NOVTABLE svc_mediaConverterI : public svc_mediaConverterNI, public CoreCallbackI {
  92. public:
  93. svc_mediaConverterI() : m_coretoken(0) { }
  94. virtual int canConvertFrom(svc_fileReader *reader, const char *name, const char *chunktype)=0;
  95. virtual const char *getConverterTo()=0;
  96. virtual int canSupportContentType(const char *contenttype) { return 0; }
  97. virtual int getInfos(MediaInfo *infos)=0;
  98. virtual int setInfos(MediaInfo *infos) { return 0; }
  99. virtual const char *getInfosXmlGroup() { return (const char *)NULL; }
  100. virtual int processData(MediaInfo *infos, ChunkList *chunk_list, bool *killswitch)=0;
  101. virtual int getPosition(void) { return -1; }
  102. virtual int getLatency(void) { return 0; }
  103. virtual int sortPlacement(const char *otherconverter) { return 0; }
  104. virtual int isSelectableOutput(void) { return 0; }
  105. virtual int onCoreUserMsg(const char *msg, const char *value) { return 0; }
  106. virtual CoreCallback *getCoreCallback(void) { return this; }
  107. virtual void setCoreToken(CoreToken t) { m_coretoken=t; }
  108. protected:
  109. CoreToken m_coretoken;
  110. };
  111. #include <api/service/servicei.h>
  112. template <class T>
  113. class MediaConverterCreator : public waServiceFactoryT<svc_mediaConverter, T> { };
  114. #endif