flv_f263_decoder.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "flv_f263_decoder.h"
  2. #include "lib.h"
  3. int FLVDecoderCreator::CreateVideoDecoder(int format_type, int width, int height, ifc_flvvideodecoder **decoder)
  4. {
  5. if (format_type == FLV::VIDEO_FORMAT_SORENSON)
  6. {
  7. void *ctx = F263_CreateDecoder();
  8. if (!ctx)
  9. return CREATEDECODER_FAILURE;
  10. *decoder = new FLVSorenson(ctx);
  11. return CREATEDECODER_SUCCESS;
  12. }
  13. return CREATEDECODER_NOT_MINE;
  14. }
  15. int FLVDecoderCreator::HandlesVideo(int format_type)
  16. {
  17. if (format_type == FLV::VIDEO_FORMAT_SORENSON)
  18. {
  19. return CREATEDECODER_SUCCESS;
  20. }
  21. return CREATEDECODER_NOT_MINE;
  22. }
  23. #define CBCLASS FLVDecoderCreator
  24. START_DISPATCH;
  25. CB(CREATE_VIDEO_DECODER, CreateVideoDecoder)
  26. CB(HANDLES_VIDEO, HandlesVideo)
  27. END_DISPATCH;
  28. #undef CBCLASS
  29. /* --- */
  30. FLVSorenson::FLVSorenson(void *decoder) : decoder(decoder)
  31. {
  32. last_timestamp=0;
  33. width=0;
  34. height=0;
  35. decoded=0;
  36. }
  37. int FLVSorenson::GetOutputFormat(int *x, int *y, int *color_format)
  38. {
  39. if (width && height)
  40. {
  41. *x = width;
  42. *y = height;
  43. *color_format = '21VY';
  44. return FLV_VIDEO_SUCCESS;
  45. }
  46. return FLV_VIDEO_FAILURE;
  47. }
  48. int FLVSorenson::DecodeSample(const void *inputBuffer, size_t inputBufferBytes, int32_t timestamp)
  49. {
  50. last_timestamp = timestamp;
  51. int keyframe;
  52. int ret = F263_DecodeFrame(decoder, const_cast<void *>(inputBuffer), inputBufferBytes, &yv12, &width, &height, &keyframe);
  53. if (ret == F263_OK)
  54. {
  55. decoded=1;
  56. return FLV_VIDEO_SUCCESS;
  57. }
  58. else
  59. return FLV_VIDEO_FAILURE;
  60. }
  61. void FLVSorenson::Flush()
  62. {
  63. }
  64. void FLVSorenson::Close()
  65. {
  66. if (decoder)
  67. F263_DestroyDecoder(decoder);
  68. delete this;
  69. }
  70. int FLVSorenson::GetPicture(void **data, void **decoder_data, uint64_t *timestamp)
  71. {
  72. if (decoded)
  73. {
  74. *timestamp = last_timestamp;
  75. *decoder_data = 0;
  76. *data = &yv12;
  77. decoded=0;
  78. return FLV_VIDEO_SUCCESS;
  79. }
  80. return FLV_VIDEO_FAILURE;
  81. }
  82. #define CBCLASS FLVSorenson
  83. START_DISPATCH;
  84. CB(FLV_VIDEO_GETOUTPUTFORMAT, GetOutputFormat)
  85. CB(FLV_VIDEO_DECODE, DecodeSample)
  86. VCB(FLV_VIDEO_FLUSH, Flush)
  87. VCB(FLV_VIDEO_CLOSE, Close)
  88. CB(FLV_VIDEO_GET_PICTURE, GetPicture)
  89. END_DISPATCH;
  90. #undef CBCLASS