mp4_mp4v_decoder.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include "mp4_mp4v_decoder.h"
  2. #include "../winamp/wa_ipc.h"
  3. MP4VMP4Decoder::MP4VMP4Decoder()
  4. {
  5. }
  6. MP4VMP4Decoder::~MP4VMP4Decoder()
  7. {
  8. }
  9. int MP4VMP4Decoder::Open(MP4FileHandle mp4_file, MP4TrackId mp4_track)
  10. {
  11. HRESULT hr;
  12. VIDEOINFOHEADER header = {0, };
  13. header.bmiHeader.biHeight = MP4GetTrackVideoHeight(mp4_file, mp4_track);
  14. header.bmiHeader.biWidth = MP4GetTrackVideoWidth(mp4_file, mp4_track);
  15. header.bmiHeader.biCompression = 'v4pm';
  16. hr = decoder.Open(&header);
  17. if (FAILED(hr)) {
  18. return MP4_VIDEO_FAILURE;
  19. }
  20. uint8_t *buffer = 0;
  21. uint32_t buffer_size = 0;
  22. if (MP4GetTrackESConfiguration(mp4_file, mp4_track, &buffer, &buffer_size)
  23. && buffer && buffer_size) {
  24. hr = decoder.Feed(buffer, buffer_size, 0);
  25. MP4Free(buffer);
  26. if (FAILED(hr)) {
  27. return MP4_VIDEO_FAILURE;
  28. }
  29. }
  30. return MP4_VIDEO_SUCCESS;
  31. }
  32. int MP4VMP4Decoder::GetOutputFormat(int *x, int *y, int *color_format, double *aspect_ratio)
  33. {
  34. UINT width, height;
  35. bool local_flip=false;
  36. if (SUCCEEDED(decoder.GetOutputFormat(&width, &height, &local_flip, aspect_ratio))) {
  37. *x = width;
  38. *y = height;
  39. *color_format = '21VY';
  40. return MP4_VIDEO_SUCCESS;
  41. }
  42. return MP4_VIDEO_FAILURE;
  43. }
  44. int MP4VMP4Decoder::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, MP4Timestamp timestamp)
  45. {
  46. HRESULT hr;
  47. hr=decoder.Feed(inputBuffer, inputBufferBytes, timestamp);
  48. return MP4_VIDEO_SUCCESS;
  49. }
  50. int MP4VMP4Decoder::CanHandleCodec(const char *codecName)
  51. {
  52. return !strcmp(codecName, "mp4v");
  53. }
  54. void MP4VMP4Decoder::Flush()
  55. {
  56. decoder.Flush();
  57. }
  58. int MP4VMP4Decoder::GetPicture(void **data, void **decoder_data, MP4Timestamp *timestamp)
  59. {
  60. if (SUCCEEDED(decoder.GetFrame((YV12_PLANES **)data, decoder_data, timestamp))) {
  61. return MP4_VIDEO_SUCCESS;
  62. } else {
  63. return MP4_VIDEO_FAILURE;
  64. }
  65. }
  66. void MP4VMP4Decoder::FreePicture(void *data, void *decoder_data)
  67. {
  68. decoder.FreeFrame((YV12_PLANES *)data, decoder_data);
  69. }
  70. void MP4VMP4Decoder::Close()
  71. {
  72. }
  73. #define CBCLASS MP4VMP4Decoder
  74. START_DISPATCH;
  75. CB(MPEG4_VIDEO_OPEN, Open)
  76. CB(MPEG4_VIDEO_GETOUTPUTFORMAT, GetOutputFormat)
  77. CB(MPEG4_VIDEO_DECODE, DecodeSample)
  78. CB(MPEG4_VIDEO_HANDLES_CODEC, CanHandleCodec)
  79. VCB(MPEG4_VIDEO_FLUSH, Flush)
  80. CB(MPEG4_VIDEO_GET_PICTURE, GetPicture)
  81. VCB(MPEG4_VIDEO_FREE_PICTURE, FreePicture)
  82. VCB(MPEG4_VIDEO_CLOSE, Close)
  83. END_DISPATCH;
  84. #undef CBCLASS