avi_mp4v_decoder.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "avi_mp4v_decoder.h"
  2. #include "../Winamp/wa_ipc.h"
  3. #include "../nsavi/read.h"
  4. #include <mmsystem.h>
  5. #include <Amvideo.h>
  6. #include <Dvdmedia.h>
  7. int AVIDecoderCreator::CreateVideoDecoder(const nsavi::AVIH *avi_header, const nsavi::STRH *stream_header, const nsavi::STRF *stream_format, const nsavi::STRD *stream_data, ifc_avivideodecoder **decoder)
  8. {
  9. nsavi::video_format *format = (nsavi::video_format *)stream_format;
  10. if (format) {
  11. if (
  12. format->compression == 'DIVX' || format->compression == 'divx' // xvid
  13. || format->compression == 'xvid' || format->compression == 'XVID' // divx
  14. || format->compression == 'v4pm' // mp4v
  15. || format->compression == '05XD' // divx 5
  16. || format->compression == nsaviFOURCC('S','E','D','G') // dunno what this is exactly
  17. /* || format->compression == '3VID' // divx 3, let's hope it plays */
  18. ) {
  19. VIDEOINFOHEADER header = {0, };
  20. //header.rcSource.right = format->width;
  21. //header.rcSource.bottom = format->height;
  22. //header.rcTarget = header.rcSource;
  23. memcpy(&header.bmiHeader, &format->video_format_size_bytes, 40);
  24. MFTDecoder *ctx = new MFTDecoder;
  25. if (!ctx) {
  26. return CREATEDECODER_FAILURE;
  27. }
  28. if (FAILED(ctx->Open(&header))) {
  29. delete ctx;
  30. return CREATEDECODER_FAILURE;
  31. }
  32. *decoder = new AVIMP4V(ctx, stream_header, format);
  33. return CREATEDECODER_SUCCESS;
  34. }
  35. }
  36. return CREATEDECODER_NOT_MINE;
  37. }
  38. #define CBCLASS AVIDecoderCreator
  39. START_DISPATCH;
  40. CB(CREATE_VIDEO_DECODER, CreateVideoDecoder)
  41. END_DISPATCH;
  42. #undef CBCLASS
  43. AVIMP4V::AVIMP4V(MFTDecoder *decoder, const nsavi::STRH *stream_header, const nsavi::video_format *stream_format)
  44. : decoder(decoder), stream_header(stream_header), stream_format(stream_format)
  45. {
  46. if (stream_format->size_bytes > 40) {
  47. //MPEG4Video_DecodeFrame(decoder, ((const uint8_t *)stream_format) + 44, stream_format->size_bytes - stream_format->video_format_size_bytes, 0);
  48. }
  49. }
  50. AVIMP4V::~AVIMP4V()
  51. {
  52. delete decoder;
  53. }
  54. int AVIMP4V::GetOutputProperties(int *x, int *y, int *color_format, double *aspect_ratio, int *flip)
  55. {
  56. UINT width, height;
  57. bool local_flip=false;
  58. if (SUCCEEDED(decoder->GetOutputFormat(&width, &height, &local_flip, aspect_ratio))) {
  59. *x = width;
  60. *y = height;
  61. *color_format = '21VY';
  62. *flip = local_flip;
  63. return AVI_SUCCESS;
  64. }
  65. return AVI_FAILURE;
  66. }
  67. int AVIMP4V::DecodeChunk(uint16_t type, const void *inputBuffer, size_t inputBufferBytes)
  68. {
  69. if (decoder) {
  70. decoder->Feed(inputBuffer, inputBufferBytes, 0);
  71. return AVI_SUCCESS;
  72. }
  73. return AVI_FAILURE;
  74. }
  75. void AVIMP4V::Flush()
  76. {
  77. if (decoder) {
  78. decoder->Flush();
  79. }
  80. }
  81. int AVIMP4V::GetPicture(void **data, void **decoder_data)
  82. {
  83. if (SUCCEEDED(decoder->GetFrame((YV12_PLANES **)data, decoder_data, 0))) {
  84. return AVI_SUCCESS;
  85. } else {
  86. return AVI_FAILURE;
  87. }
  88. }
  89. void AVIMP4V::FreePicture(void *data, void *decoder_data)
  90. {
  91. decoder->FreeFrame((YV12_PLANES *)data, decoder_data);
  92. }
  93. void AVIMP4V::EndOfStream()
  94. {
  95. decoder->Drain();
  96. }
  97. void AVIMP4V::HurryUp(int state)
  98. {
  99. //if (decoder)
  100. //MPEG4Video_HurryUp(decoder, state);
  101. }
  102. void AVIMP4V::Close()
  103. {
  104. delete this;
  105. }
  106. #define CBCLASS AVIMP4V
  107. START_DISPATCH;
  108. CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
  109. CB(DECODE_CHUNK, DecodeChunk)
  110. VCB(FLUSH, Flush)
  111. CB(GET_PICTURE, GetPicture)
  112. VCB(FREE_PICTURE, FreePicture)
  113. VCB(END_OF_STREAM, EndOfStream)
  114. VCB(HURRY_UP, HurryUp)
  115. VCB(CLOSE, Close)
  116. END_DISPATCH;
  117. #undef CBCLASS