1
0

VideoDataConverter.cpp 842 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "main.h"
  2. #include "VideoDataConverter.h"
  3. #include <cassert>
  4. class YV12Converter : public VideoDataConverter
  5. {
  6. public:
  7. YV12Converter(int w, int h)
  8. : width(w), height(h)
  9. {
  10. yv12.y.rowBytes = width;
  11. yv12.v.rowBytes = width / 2;
  12. yv12.u.rowBytes = width / 2;
  13. vOffset = width*height;
  14. uOffset = width*height/4;
  15. }
  16. void *Convert(void *videoData)
  17. {
  18. yv12.y.baseAddr = (unsigned char*)videoData;
  19. yv12.v.baseAddr = yv12.y.baseAddr + vOffset;
  20. yv12.u.baseAddr = yv12.v.baseAddr + uOffset;
  21. return (void *)&yv12;
  22. }
  23. int width, height;
  24. int vOffset, uOffset;
  25. YV12_PLANES yv12;
  26. };
  27. VideoDataConverter *MakeConverter(VideoOutputStream *stream)
  28. {
  29. switch (stream->FourCC())
  30. {
  31. case '21VY':
  32. return new YV12Converter(stream->DestinationWidth(), stream->DestinationHeight());
  33. default:
  34. return new VideoDataConverter;
  35. }
  36. }