mczarnek

BitstreamIO class

Feb 3rd, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include "bitstreamIO.h"
  2. #include <fstream>
  3. #include <iostream>
  4. //#include "sample_defs.h"
  5. //#include "exceptions.h"
  6.  
  7. BitstreamIO::BitstreamIO(mfxBitstream *h264Bitstream)
  8. {
  9.     h264BitstreamLength = sizeof(h264Bitstream);
  10.     curH264Bitstream = (mfxBitstream *)malloc(sizeof(h264Bitstream));
  11. }
  12.  
  13. BitstreamIO::~BitstreamIO()
  14. {
  15.  
  16. }
  17.  
  18. void BitstreamIO::switchStreams(mfxBitstream *h264Bitstream)
  19. {
  20.     free(curH264Bitstream->Data);
  21.     free(curH264Bitstream);
  22.     //h264BitstreamLength = sizeof(h264Bitstream);
  23.     curH264Bitstream = (mfxBitstream *)malloc(sizeof(h264Bitstream));
  24.     memset(curH264Bitstream,0,sizeof(curH264Bitstream));
  25.  
  26.     curH264Bitstream->Data = (mfxU8 *)malloc(h264Bitstream->DataLength);
  27.     curH264Bitstream->DataLength = h264Bitstream->DataLength;
  28.     curH264Bitstream->DataOffset = h264Bitstream->DataOffset;
  29.     curH264Bitstream->MaxLength = h264Bitstream->MaxLength;
  30.  
  31.     memcpy(curH264Bitstream->Data,h264Bitstream->Data,h264Bitstream->DataLength);
  32. }
  33.  
  34. //Only function needed since only using this class to read a h264 frame from a bitstream
  35. //Note: must remember to free outBitstream later
  36. mfxI32 BitstreamIO::Read(mfxBitstream *outBitstream)
  37. {
  38.     //Again, not thread safe
  39.     //outBitstream=h264BitstreamPtr;
  40.    
  41.     outBitstream->DataLength = curH264Bitstream->DataLength;
  42.     outBitstream->DataFlag = curH264Bitstream->DataFlag;
  43.     outBitstream->DataOffset = curH264Bitstream->DataOffset;
  44.     outBitstream->MaxLength = curH264Bitstream->MaxLength;
  45.     outBitstream->TimeStamp = curH264Bitstream->TimeStamp;
  46.  
  47.     if(curH264Bitstream->Data != NULL)
  48.     {
  49.         if(outBitstream->Data != NULL)
  50.         {
  51.             free(outBitstream->Data);
  52.         }
  53.  
  54.         if(outBitstream->DataLength != 0)
  55.         {
  56.             outBitstream->Data = (mfxU8 *)malloc(curH264Bitstream->DataLength);
  57.             memcpy(outBitstream->Data,curH264Bitstream->Data,outBitstream->DataLength);
  58.         }
  59.     }
  60.  
  61.     mfxI32 nBytesRead = h264BitstreamLength;
  62.  
  63.     return nBytesRead;
  64. }
  65.  
  66. //Do not currently need to use if only using this class to read a h264 frame from a bitstream
  67. mfxI32 BitstreamIO::Write(mfxBitstream *outBitStream)
  68. {
  69.     return 0;
  70. }
  71.  
  72. //Do not currently need to use if only using this class to read a h264 frame from a bitstream
  73. mfxI64 BitstreamIO::Seek(mfxI64 offset, mfxSeekOrigin origin)
  74. {
  75.     return origin;
  76. }
Add Comment
Please, Sign In to add comment