PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/Avidemux/avidemux/ADM_outputs/oplug_dummy/oplug_dummy.cpp

http://mulder.googlecode.com/
C++ | 237 lines | 163 code | 45 blank | 29 comment | 24 complexity | b70ca6828885ef35043780c96c8be1ed MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0, AGPL-1.0, GPL-3.0
  1. /***************************************************************************
  2. oplug_dummy.cpp - Container that discards all inputs
  3. Video only!
  4. -------------------
  5. copyright : (C) 2007 by mean
  6. email : fixounet@free.fr
  7. ***************************************************************************/
  8. /***************************************************************************
  9. * *
  10. * This program is free software; you can redistribute it and/or modify *
  11. * it under the terms of the GNU General Public License as published by *
  12. * the Free Software Foundation; either version 2 of the License, or *
  13. * (at your option) any later version. *
  14. * *
  15. ***************************************************************************/
  16. #define __STDC_LIMIT_MACROS
  17. #include <math.h>
  18. #include "config.h"
  19. #include "ADM_default.h"
  20. #include "ADM_threads.h"
  21. extern "C" {
  22. #include "ADM_lavcodec.h"
  23. };
  24. #include "ADM_editor/ADM_Video.h"
  25. #include "DIA_coreToolkit.h"
  26. #include "ADM_videoFilter.h"
  27. #include "ADM_videoFilter_internal.h"
  28. #include "ADM_encoder/ADM_vidEncode.hxx"
  29. #include "ADM_codecs/ADM_codec.h"
  30. #include "ADM_encoder/adm_encoder.h"
  31. #include "../oplug_mpegFF/oplug_vcdff.h"
  32. #include "ADM_userInterfaces/ADM_commonUI/DIA_encoding.h"
  33. #include "ADM_audiofilter/audioprocess.hxx"
  34. #include "ADM_audiofilter/audioeng_buildfilters.h"
  35. #include "../ADM_lavformat.h"
  36. #include "fourcc.h"
  37. #include "ADM_encoder/adm_encConfig.h"
  38. #include "ADM_encoder/ADM_vidEncode.hxx"
  39. #include "ADM_libraries/ADM_mplex/ADM_mthread.h"
  40. #include "ADM_toolkit/ADM_audioQueue.h"
  41. #include "ADM_osSupport/ADM_debugID.h"
  42. #define MODULE_NAME MODULE_MP4
  43. #include "ADM_osSupport/ADM_debug.h"
  44. extern void UI_purge(void );
  45. extern uint32_t videoProcessMode (void);
  46. extern uint32_t frameStart,frameEnd;
  47. static uint8_t *_buffer=NULL,*_outbuffer=NULL;
  48. /*
  49. * \fn Oplug_dummy
  50. \brief Main function to save in dummy format.
  51. This containers drops all datas. Useful for testing or some weird filters
  52. */
  53. uint8_t oplug_dummy(const char *name)
  54. {
  55. AVDMGenericVideoStream *_incoming=NULL;
  56. AVDMGenericAudioStream *audio=NULL;
  57. uint8_t audioBuffer[48000];
  58. uint8_t *videoBuffer=NULL;
  59. uint32_t alen;//,flags;
  60. uint32_t size;
  61. uint32_t sample_got=0,sample;
  62. uint32_t extraDataSize=0;
  63. uint8_t *extraData=NULL;
  64. aviInfo info;
  65. uint32_t width,height;
  66. DIA_encoding *encoding_gui=NULL;
  67. Encoder *_encode=NULL;
  68. uint32_t total=0;
  69. uint32_t videoExtraDataSize=0;
  70. uint8_t *videoExtraData=NULL;
  71. uint8_t *dummy,err;
  72. int prefill=0;
  73. uint32_t displayFrame=0;
  74. ADMBitstream bitstream(0);
  75. uint32_t frameWrite=0;
  76. uint8_t r=0;
  77. int frameDelay = 0;
  78. bool receivedFrame = false;
  79. uint32_t totalAudioSize=0;
  80. // Setup video
  81. if(videoProcessMode())
  82. {
  83. _incoming = getLastVideoFilter (frameStart,frameEnd-frameStart);
  84. }else
  85. {
  86. _incoming = getFirstVideoFilter (frameStart,frameEnd-frameStart);
  87. }
  88. videoBuffer=new uint8_t[_incoming->getInfo()->width*_incoming->getInfo()->height*3];
  89. // Set global header encoding, needed for H264
  90. _encode = getVideoEncoder(1);
  91. total= _incoming->getInfo()->nb_frames;
  92. info.fcc=*(uint32_t *)_encode->getCodecName(); //FIXME
  93. encoding_gui=new DIA_encoding(_incoming->getInfo()->fps1000);
  94. bitstream.bufferSize=_incoming->getInfo()->width*_incoming->getInfo()->height*3;
  95. if (!_encode)
  96. {
  97. GUI_Error_HIG ("[FLV]",QT_TR_NOOP("Cannot initialize the video stream"));
  98. goto stopit;
  99. }
  100. // init compressor
  101. encoding_gui->setContainer(QT_TR_NOOP("Dummy"));
  102. encoding_gui->setAudioCodec(QT_TR_NOOP("None"));
  103. if(!videoProcessMode())
  104. encoding_gui->setCodec(QT_TR_NOOP("Copy"));
  105. else
  106. encoding_gui->setCodec(_encode->getDisplayName());
  107. if (!_encode->configure (_incoming, 0))
  108. {
  109. GUI_Error_HIG (QT_TR_NOOP("Filter init failed"), NULL);
  110. goto stopit;
  111. };
  112. encoding_gui->setPhasis (QT_TR_NOOP("Encoding"));
  113. info.width=_incoming->getInfo()->width;
  114. info.height=_incoming->getInfo()->height;
  115. info.nb_frames=_incoming->getInfo()->nb_frames;
  116. info.fps1000=_incoming->getInfo()->fps1000;
  117. _encode->hasExtraHeaderData( &videoExtraDataSize,&dummy);
  118. if(videoExtraDataSize)
  119. {
  120. printf("We have extradata for video in copy mode (%d)\n",videoExtraDataSize);
  121. videoExtraData=new uint8_t[videoExtraDataSize];
  122. memcpy(videoExtraData,dummy,videoExtraDataSize);
  123. }
  124. // _________________Setup video (cont) _______________
  125. // ___________ Read 1st frame _________________
  126. ADM_assert(_encode);
  127. bitstream.data=videoBuffer;
  128. if(!videoProcessMode())
  129. encoding_gui->setCodec(QT_TR_NOOP("Copy"));
  130. else
  131. encoding_gui->setCodec(_encode->getDisplayName());
  132. UI_purge();
  133. for (uint32_t frame = 0; frame < total; frame++)
  134. {
  135. if (!encoding_gui->isAlive())
  136. {
  137. r = 0;
  138. break;
  139. }
  140. for (;;)
  141. {
  142. bitstream.cleanup(frame);
  143. if (frame + frameDelay >= total)
  144. {
  145. if (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH)
  146. r = _encode->encode(UINT32_MAX, &bitstream);
  147. else
  148. r = 0;
  149. }
  150. else
  151. r = _encode->encode(frame + frameDelay, &bitstream);
  152. if (!r)
  153. {
  154. printf("Encoding of frame %lu failed!\n", frame);
  155. GUI_Error_HIG (QT_TR_NOOP("Error while encoding"), NULL);
  156. break;
  157. }
  158. else if (!receivedFrame && bitstream.len > 0)
  159. {
  160. if (!(bitstream.flags & AVI_KEY_FRAME))
  161. {
  162. GUI_Error_HIG (QT_TR_NOOP("KeyFrame error"), QT_TR_NOOP("The beginning frame is not a key frame.\nPlease move the A marker."));
  163. r = 0;
  164. break;
  165. }
  166. else
  167. receivedFrame = true;
  168. }
  169. if (bitstream.len == 0 && (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH))
  170. {
  171. printf("skipping frame: %u size: %i\n", frame + frameDelay, bitstream.len);
  172. frameDelay++;
  173. }
  174. else
  175. break;
  176. }
  177. if (!r)
  178. break;
  179. encoding_gui->setFrame(frame, bitstream.len, bitstream.out_quantizer, total);
  180. }
  181. encoding_gui->reset();
  182. stopit:
  183. if(encoding_gui) delete encoding_gui;
  184. if(videoBuffer) delete [] videoBuffer;
  185. if(_encode) delete _encode;
  186. if(videoExtraData) delete [] videoExtraData;
  187. return r;
  188. }
  189. // EOF