mpeg4video.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef NULLSOFT_MPEG4VIDEO_H
  2. #define NULLSOFT_MPEG4VIDEO_H
  3. #include "../external_dependencies/libmp4v2/mp4.h"
  4. #include <bfc/dispatch.h>
  5. #include <api/service/services.h>
  6. enum
  7. {
  8. MP4_VIDEO_SUCCESS = 0,
  9. MP4_VIDEO_FAILURE = 1,
  10. MP4_VIDEO_OUTPUT_FORMAT_CHANGED = -1, // succeeded, but call GetOutputFormat again!
  11. MP4_VIDEO_AGAIN = -2,
  12. };
  13. class MP4VideoDecoder : public Dispatchable
  14. {
  15. protected:
  16. MP4VideoDecoder() {}
  17. ~MP4VideoDecoder() {}
  18. public:
  19. static FOURCC getServiceType() { return WaSvc::MP4VIDEODECODER; }
  20. int Open(MP4FileHandle mp4_file, MP4TrackId mp4_track);
  21. int GetOutputFormat(int *x, int *y, int *color_format, double *aspect_ratio);
  22. int DecodeSample(const void *inputBuffer, size_t inputBufferBytes, MP4Timestamp timestamp);
  23. void Flush();
  24. void Close();
  25. int CanHandleCodec(const char *codecName); // return 0 for no, anything else for yes
  26. int GetPicture(void **data, void **decoder_data, MP4Timestamp *timestamp);
  27. void FreePicture(void *data, void *decoder_data);
  28. void HurryUp(int state);
  29. DISPATCH_CODES
  30. {
  31. MPEG4_VIDEO_OPEN = 11,
  32. MPEG4_VIDEO_GETOUTPUTFORMAT = 21,
  33. MPEG4_VIDEO_DECODE = 31,
  34. MPEG4_VIDEO_FLUSH = 40,
  35. MPEG4_VIDEO_CLOSE = 50,
  36. MPEG4_VIDEO_HANDLES_CODEC = 60,
  37. MPEG4_VIDEO_GET_PICTURE = 70,
  38. MPEG4_VIDEO_FREE_PICTURE = 80,
  39. MPEG4_VIDEO_HURRY_UP = 90,
  40. };
  41. };
  42. inline int MP4VideoDecoder::Open(MP4FileHandle mp4_file, MP4TrackId mp4_track)
  43. {
  44. return _call(MPEG4_VIDEO_OPEN, (int)MP4_VIDEO_FAILURE, mp4_file, mp4_track);
  45. }
  46. inline int MP4VideoDecoder::GetOutputFormat(int *x, int *y, int *color_format, double *aspect_ratio)
  47. {
  48. return _call(MPEG4_VIDEO_GETOUTPUTFORMAT, (int)MP4_VIDEO_FAILURE, x, y, color_format, aspect_ratio);
  49. }
  50. inline int MP4VideoDecoder::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, MP4Timestamp timestamp)
  51. {
  52. return _call(MPEG4_VIDEO_DECODE, (int)MP4_VIDEO_FAILURE, inputBuffer, inputBufferBytes, timestamp);
  53. }
  54. inline void MP4VideoDecoder::Flush()
  55. {
  56. _voidcall(MPEG4_VIDEO_FLUSH);
  57. }
  58. inline void MP4VideoDecoder::Close()
  59. {
  60. _voidcall(MPEG4_VIDEO_CLOSE);
  61. }
  62. inline int MP4VideoDecoder::CanHandleCodec(const char *codecName)
  63. {
  64. return _call(MPEG4_VIDEO_HANDLES_CODEC, (int)0, codecName);
  65. }
  66. inline int MP4VideoDecoder::GetPicture(void **data, void **decoder_data, MP4Timestamp *timestamp)
  67. {
  68. return _call(MPEG4_VIDEO_GET_PICTURE, (int)MP4_VIDEO_FAILURE, data, decoder_data, timestamp);
  69. }
  70. inline void MP4VideoDecoder::FreePicture(void *data, void *decoder_data)
  71. {
  72. _voidcall(MPEG4_VIDEO_FREE_PICTURE, data, decoder_data);
  73. }
  74. inline void MP4VideoDecoder::HurryUp(int state)
  75. {
  76. _voidcall(MPEG4_VIDEO_HURRY_UP, state);
  77. }
  78. #endif