home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Riza / source / vc_dv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  4.1 KB  |  147 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    A/V interface library
  3. //    Copyright (C) 1998-2004 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #include <vd2/system/error.h>
  20. #include <vd2/system/vdalloc.h>
  21. #include <vd2/Kasumi/pixmap.h>
  22. #include <vd2/Kasumi/pixmapops.h>
  23. #include <vd2/Kasumi/pixmaputils.h>
  24. #include <vd2/Riza/bitmap.h>
  25. #include <vd2/Riza/videocodec.h>
  26. #include <vd2/Meia/decode_dv.h>
  27.  
  28. class VDVideoDecompressorDV : public IVDVideoDecompressor {
  29. public:
  30.     VDVideoDecompressorDV(int w, int h);
  31.     ~VDVideoDecompressorDV();
  32.  
  33.     bool QueryTargetFormat(int format);
  34.     bool QueryTargetFormat(const void *format);
  35.     bool SetTargetFormat(int format);
  36.     bool SetTargetFormat(const void *format);
  37.     int GetTargetFormat() { return mFormat; }
  38.     int GetTargetFormatVariant() { return 0; }
  39.     const uint32 *GetTargetFormatPalette() { return NULL; }
  40.     void Start();
  41.     void Stop();
  42.     void DecompressFrame(void *dst, const void *src, uint32 srcSize, bool keyframe, bool preroll);
  43.     const void *GetRawCodecHandlePtr();
  44.     const wchar_t *GetName();
  45.  
  46. protected:
  47.     int    mFormat;
  48.     int    mWidth;
  49.     int    mHeight;
  50.  
  51.     vdautoptr<IVDVideoDecoderDV> mpDecoder;
  52. };
  53.  
  54. IVDVideoDecompressor *VDCreateVideoDecompressorDV(int w, int h) {
  55.     return new VDVideoDecompressorDV(w, h);
  56. }
  57.  
  58. VDVideoDecompressorDV::VDVideoDecompressorDV(int w, int h)
  59.     : mFormat(0)
  60.     , mWidth(w)
  61.     , mHeight(h)
  62.     , mpDecoder(VDCreateVideoDecoderDV())
  63. {
  64. }
  65.  
  66. VDVideoDecompressorDV::~VDVideoDecompressorDV() {
  67. }
  68.  
  69. bool VDVideoDecompressorDV::QueryTargetFormat(int format) {
  70.     return format > 0;
  71. }
  72.  
  73. bool VDVideoDecompressorDV::QueryTargetFormat(const void *format) {
  74.     const VDAVIBitmapInfoHeader& hdr = *(const VDAVIBitmapInfoHeader *)format;
  75.  
  76.     if (hdr.biWidth != mWidth || hdr.biHeight != mHeight)
  77.         return false;
  78.  
  79.     int pxformat = VDBitmapFormatToPixmapFormat(hdr);
  80.  
  81.     return QueryTargetFormat(pxformat);
  82. }
  83.  
  84. bool VDVideoDecompressorDV::SetTargetFormat(int format) {
  85.     if (!format)
  86.         format = nsVDPixmap::kPixFormat_YUV422_YUYV;
  87.  
  88.     if (QueryTargetFormat(format)) {
  89.         mFormat = format;
  90.         return true;
  91.     }
  92.  
  93.     return false;
  94. }
  95.  
  96. bool VDVideoDecompressorDV::SetTargetFormat(const void *format) {
  97.     const VDAVIBitmapInfoHeader& hdr = *(const VDAVIBitmapInfoHeader *)format;
  98.  
  99.     if (hdr.biWidth != mWidth || hdr.biHeight != mHeight)
  100.         return false;
  101.  
  102.     int pxformat = VDBitmapFormatToPixmapFormat(hdr);
  103.  
  104.     if (QueryTargetFormat(pxformat)) {
  105.         mFormat = pxformat;
  106.         return true;
  107.     }
  108.  
  109.     return false;
  110. }
  111.  
  112. void VDVideoDecompressorDV::Start() {
  113.     if (!mFormat)
  114.         throw MyError("Cannot find compatible target format for video decompression.");
  115. }
  116.  
  117. void VDVideoDecompressorDV::Stop() {
  118. }
  119.  
  120. void VDVideoDecompressorDV::DecompressFrame(void *dst, const void *src, uint32 srcSize, bool keyframe, bool preroll) {
  121.     if (!mFormat)
  122.         throw MyError("Cannot find compatible target format for video decompression.");
  123.  
  124.     if ((mHeight == 480 && srcSize != 120000) || (mHeight == 576 && srcSize != 144000))
  125.         throw MyError("DV frame data is wrong size (truncated or corrupted)");
  126.  
  127.     mpDecoder->DecompressFrame(src, mHeight == 576);
  128.  
  129.     // blit time!
  130.  
  131.     VDPixmap pxsrc(mpDecoder->GetFrameBuffer());
  132.  
  133.     VDPixmapLayout dstlayout;
  134.     VDMakeBitmapCompatiblePixmapLayout(dstlayout, mWidth, mHeight, mFormat, 0);
  135.     VDPixmap pxdst(VDPixmapFromLayout(dstlayout, dst));
  136.  
  137.     VDPixmapBlt(pxdst, pxsrc);
  138. }
  139.  
  140. const void *VDVideoDecompressorDV::GetRawCodecHandlePtr() {
  141.     return NULL;
  142. }
  143.  
  144. const wchar_t *VDVideoDecompressorDV::GetName() {
  145.     return L"Internal DV decoder";
  146. }
  147.