PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/Codec/Avidemux-EditorPlugin/avidemux-2.4.4/avidemux/ADM_outputs/oplug_dummy/oplug_dummy.cpp

https://bitbucket.org/gianni/vaet
C++ | 248 lines | 172 code | 47 blank | 29 comment | 24 complexity | 70bc3af56ccd55308b8265396934f5c8 MD5 | raw file
Possible License(s): 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 "config.h"
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <math.h>
  22. #include <pthread.h>
  23. #define WIN32_CLASH
  24. extern "C" {
  25. #include "ADM_lavcodec.h"
  26. };
  27. #include "default.h"
  28. #include "ADM_editor/ADM_Video.h"
  29. #include "ADM_colorspace/colorspace.h"
  30. #include "ADM_toolkit/toolkit.hxx"
  31. #include "ADM_assert.h"
  32. #include "ADM_video/ADM_genvideo.hxx"
  33. #include "ADM_filter/video_filters.h"
  34. #include "ADM_encoder/ADM_vidEncode.hxx"
  35. #include "ADM_codecs/ADM_codec.h"
  36. #include "ADM_encoder/adm_encoder.h"
  37. #include "ADM_codecs/ADM_ffmpeg.h"
  38. #include "ADM_encoder/adm_encffmpeg.h"
  39. #include "oplug_mpegFF/oplug_vcdff.h"
  40. #include "DIA_encoding.h"
  41. #include "ADM_audiofilter/audioprocess.hxx"
  42. #include "ADM_audiofilter/audioeng_buildfilters.h"
  43. #include "ADM_lavformat/ADM_lavformat.h"
  44. #include "ADM_utilities/fourcc.h"
  45. #include "ADM_encoder/adm_encConfig.h"
  46. #include "ADM_encoder/ADM_vidEncode.hxx"
  47. #include "ADM_mplex/ADM_mthread.h"
  48. #include "ADM_toolkit/ADM_audioQueue.h"
  49. #include "ADM_osSupport/ADM_debugID.h"
  50. #define MODULE_NAME MODULE_MP4
  51. #include "ADM_osSupport/ADM_debug.h"
  52. extern void UI_purge(void );
  53. extern uint32_t videoProcessMode (void);
  54. extern uint32_t frameStart,frameEnd;
  55. extern SelectCodecType current_codec;
  56. static uint8_t *_buffer=NULL,*_outbuffer=NULL;
  57. /*
  58. * \fn Oplug_dummy
  59. \brief Main function to save in dummy format.
  60. This containers drops all datas. Useful for testing or some weird filters
  61. */
  62. uint8_t oplug_dummy(const char *name)
  63. {
  64. AVDMGenericVideoStream *_incoming=NULL;
  65. AVDMGenericAudioStream *audio=NULL;
  66. uint8_t audioBuffer[48000];
  67. uint8_t *videoBuffer=NULL;
  68. uint32_t alen;//,flags;
  69. uint32_t size;
  70. uint32_t sample_got=0,sample;
  71. uint32_t extraDataSize=0;
  72. uint8_t *extraData=NULL;
  73. aviInfo info;
  74. uint32_t width,height;
  75. DIA_encoding *encoding_gui=NULL;
  76. Encoder *_encode=NULL;
  77. uint32_t total=0;
  78. uint32_t videoExtraDataSize=0;
  79. uint8_t *videoExtraData=NULL;
  80. uint8_t *dummy,err;
  81. int prefill=0;
  82. uint32_t displayFrame=0;
  83. ADMBitstream bitstream(0);
  84. uint32_t frameWrite=0;
  85. uint8_t r=0;
  86. int frameDelay = 0;
  87. bool receivedFrame = false;
  88. uint32_t totalAudioSize=0;
  89. // Setup video
  90. if(videoProcessMode())
  91. {
  92. _incoming = getLastVideoFilter (frameStart,frameEnd-frameStart);
  93. }else
  94. {
  95. _incoming = getFirstVideoFilter (frameStart,frameEnd-frameStart);
  96. }
  97. videoBuffer=new uint8_t[_incoming->getInfo()->width*_incoming->getInfo()->height*3];
  98. // Set global header encoding, needed for H264
  99. _encode = getVideoEncoder (_incoming->getInfo()->width, _incoming->getInfo()->height,1);
  100. total= _incoming->getInfo()->nb_frames;
  101. info.fcc=*(uint32_t *)_encode->getCodecName(); //FIXME
  102. encoding_gui=new DIA_encoding(_incoming->getInfo()->fps1000);
  103. bitstream.bufferSize=_incoming->getInfo()->width*_incoming->getInfo()->height*3;
  104. if (!_encode)
  105. {
  106. GUI_Error_HIG ("[FLV]",QT_TR_NOOP("Cannot initialize the video stream"));
  107. goto stopit;
  108. }
  109. // init compressor
  110. encoding_gui->setContainer(QT_TR_NOOP("Dummy"));
  111. encoding_gui->setAudioCodec(QT_TR_NOOP("None"));
  112. if(!videoProcessMode())
  113. encoding_gui->setCodec(QT_TR_NOOP("Copy"));
  114. else
  115. encoding_gui->setCodec(_encode->getDisplayName());
  116. if (!_encode->configure (_incoming))
  117. {
  118. GUI_Error_HIG (QT_TR_NOOP("Filter init failed"), NULL);
  119. goto stopit;
  120. };
  121. encoding_gui->setPhasis (QT_TR_NOOP("Encoding"));
  122. info.width=_incoming->getInfo()->width;
  123. info.height=_incoming->getInfo()->height;
  124. info.nb_frames=_incoming->getInfo()->nb_frames;
  125. info.fps1000=_incoming->getInfo()->fps1000;
  126. _encode->hasExtraHeaderData( &videoExtraDataSize,&dummy);
  127. if(videoExtraDataSize)
  128. {
  129. printf("We have extradata for video in copy mode (%d)\n",videoExtraDataSize);
  130. videoExtraData=new uint8_t[videoExtraDataSize];
  131. memcpy(videoExtraData,dummy,videoExtraDataSize);
  132. }
  133. // _________________Setup video (cont) _______________
  134. // ___________ Read 1st frame _________________
  135. ADM_assert(_encode);
  136. bitstream.data=videoBuffer;
  137. if(!videoProcessMode())
  138. encoding_gui->setCodec(QT_TR_NOOP("Copy"));
  139. else
  140. encoding_gui->setCodec(_encode->getDisplayName());
  141. UI_purge();
  142. for (uint32_t frame = 0; frame < total; frame++)
  143. {
  144. if (!encoding_gui->isAlive())
  145. {
  146. r = 0;
  147. break;
  148. }
  149. for (;;)
  150. {
  151. bitstream.cleanup(frame);
  152. if (frame + frameDelay >= total)
  153. {
  154. if (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH)
  155. r = _encode->encode(UINT32_MAX, &bitstream);
  156. else
  157. r = 0;
  158. }
  159. else
  160. r = _encode->encode(frame + frameDelay, &bitstream);
  161. if (!r)
  162. {
  163. printf("Encoding of frame %lu failed!\n", frame);
  164. GUI_Error_HIG (QT_TR_NOOP("Error while encoding"), NULL);
  165. break;
  166. }
  167. else if (!receivedFrame && bitstream.len > 0)
  168. {
  169. if (!(bitstream.flags & AVI_KEY_FRAME))
  170. {
  171. GUI_Error_HIG (QT_TR_NOOP("KeyFrame error"), QT_TR_NOOP("The beginning frame is not a key frame.\nPlease move the A marker."));
  172. r = 0;
  173. break;
  174. }
  175. else
  176. receivedFrame = true;
  177. }
  178. if (bitstream.len == 0 && (_encode->getRequirements() & ADM_ENC_REQ_NULL_FLUSH))
  179. {
  180. printf("skipping frame: %u size: %i\n", frame + frameDelay, bitstream.len);
  181. frameDelay++;
  182. }
  183. else
  184. break;
  185. }
  186. if (!r)
  187. break;
  188. encoding_gui->setFrame(frame, bitstream.len, bitstream.out_quantizer, total);
  189. }
  190. encoding_gui->reset();
  191. stopit:
  192. if(encoding_gui) delete encoding_gui;
  193. if(videoBuffer) delete [] videoBuffer;
  194. if(_encode) delete _encode;
  195. if(videoExtraData) delete [] videoExtraData;
  196. return r;
  197. }
  198. // EOF