avi_yuv_decoder.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "avi_yuv_decoder.h"
  2. #include "../Winamp/wa_ipc.h"
  3. #include <limits.h>
  4. #include <bfc/error.h>
  5. #include <intsafe.h>
  6. int BMP_GetMallocSize(int32_t height, int32_t width, int32_t bits_per_pixel, size_t *out_frame_bytes);
  7. AVIYUV *AVIYUV::CreateDecoder(nsavi::video_format *stream_format)
  8. {
  9. AVIYUV *decoder = new AVIYUV( stream_format);
  10. if (!decoder)
  11. {
  12. return 0;
  13. }
  14. if (decoder->Initialize() != NErr_Success)
  15. {
  16. delete decoder;
  17. return 0;
  18. }
  19. return decoder;
  20. }
  21. AVIYUV::AVIYUV(nsavi::video_format *stream_format) : stream_format(stream_format)
  22. {
  23. video_frame=0;
  24. video_frame_size_bytes=0;
  25. o=false;
  26. }
  27. AVIYUV::~AVIYUV()
  28. {
  29. free(video_frame);
  30. }
  31. int AVIYUV::Initialize()
  32. {
  33. size_t frame_bytes;
  34. int ret = BMP_GetMallocSize(stream_format->height, stream_format->width, 16, &frame_bytes);
  35. if (ret != NErr_Success)
  36. return ret;
  37. video_frame=malloc(frame_bytes);
  38. if (!video_frame)
  39. return NErr_OutOfMemory;
  40. video_frame_size_bytes = frame_bytes;
  41. return NErr_Success;
  42. }
  43. int AVIYUV::GetOutputProperties(int *x, int *y, int *color_format, double *aspect_ratio, int *flip)
  44. {
  45. if (stream_format)
  46. {
  47. *x = stream_format->width;
  48. *y = stream_format->height;
  49. //*flip = 1;
  50. *color_format = stream_format->compression;
  51. return AVI_SUCCESS;
  52. }
  53. return AVI_FAILURE;
  54. }
  55. int AVIYUV::DecodeChunk(uint16_t type, const void *inputBuffer, size_t inputBufferBytes)
  56. {
  57. if (stream_format)
  58. {
  59. if (video_frame_size_bytes < inputBufferBytes)
  60. return AVI_FAILURE;
  61. memcpy(video_frame, inputBuffer, inputBufferBytes);
  62. //video_frame = inputBuffer; // heh
  63. o=true;
  64. return AVI_SUCCESS;
  65. }
  66. return AVI_FAILURE;
  67. }
  68. void AVIYUV::Flush()
  69. {
  70. }
  71. int AVIYUV::GetPicture(void **data, void **decoder_data)
  72. {
  73. if (o && video_frame)
  74. {
  75. *data =(void *) video_frame;
  76. *decoder_data=0;
  77. //video_frame=0;
  78. o=false;
  79. //video_outputted=true;
  80. return AVI_SUCCESS;
  81. }
  82. return AVI_FAILURE;
  83. }
  84. void AVIYUV::Close()
  85. {
  86. delete this;
  87. }
  88. #define CBCLASS AVIYUV
  89. START_DISPATCH;
  90. CB(GET_OUTPUT_PROPERTIES, GetOutputProperties)
  91. CB(DECODE_CHUNK, DecodeChunk)
  92. VCB(FLUSH, Flush)
  93. VCB(CLOSE, Close)
  94. CB(GET_PICTURE, GetPicture)
  95. END_DISPATCH;
  96. #undef CBCLASS