Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

container_reader.c 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "mmal.h"
  26. #include "core/mmal_component_private.h"
  27. #include "core/mmal_port_private.h"
  28. #include "mmal_logging.h"
  29. #include "containers/containers.h"
  30. #include "containers/containers_codecs.h"
  31. #include "containers/core/containers_utils.h"
  32. #define READER_MAX_URI_LENGTH 1024
  33. #define WRITER_PORTS_NUM 3 /**< 3 ports should be enough for video + audio + subpicture */
  34. /* Buffering requirements */
  35. #define READER_MIN_BUFFER_SIZE (2*1024)
  36. #define READER_MIN_BUFFER_NUM 1
  37. #define READER_RECOMMENDED_BUFFER_SIZE (32*1024)
  38. #define READER_RECOMMENDED_BUFFER_NUM 10
  39. /*****************************************************************************/
  40. /** Private context for this component */
  41. typedef struct MMAL_COMPONENT_MODULE_T
  42. {
  43. VC_CONTAINER_T *container;
  44. char uri[READER_MAX_URI_LENGTH+1];
  45. unsigned int ports;
  46. MMAL_BOOL_T writer;
  47. MMAL_BOOL_T error;
  48. /* Reader specific */
  49. MMAL_BOOL_T packet_logged;
  50. /* Writer specific */
  51. unsigned int port_last_used;
  52. unsigned int port_writing_frame;
  53. } MMAL_COMPONENT_MODULE_T;
  54. typedef struct MMAL_PORT_MODULE_T
  55. {
  56. unsigned int track;
  57. MMAL_QUEUE_T *queue;
  58. MMAL_BOOL_T flush;
  59. MMAL_BOOL_T eos;
  60. VC_CONTAINER_ES_FORMAT_T *format; /**< Format description for the elementary stream */
  61. } MMAL_PORT_MODULE_T;
  62. /*****************************************************************************/
  63. static struct {
  64. VC_CONTAINER_FOURCC_T codec;
  65. MMAL_FOURCC_T encoding;
  66. VC_CONTAINER_FOURCC_T codec_variant;
  67. MMAL_FOURCC_T encoding_variant;
  68. } encoding_table[] =
  69. {
  70. {VC_CONTAINER_CODEC_H263, MMAL_ENCODING_H263, 0, 0},
  71. {VC_CONTAINER_CODEC_H264, MMAL_ENCODING_H264, 0, 0},
  72. {VC_CONTAINER_CODEC_H264, MMAL_ENCODING_H264,
  73. VC_CONTAINER_VARIANT_H264_AVC1, MMAL_ENCODING_VARIANT_H264_AVC1},
  74. {VC_CONTAINER_CODEC_H264, MMAL_ENCODING_H264,
  75. VC_CONTAINER_VARIANT_H264_RAW, MMAL_ENCODING_VARIANT_H264_RAW},
  76. {VC_CONTAINER_CODEC_MP4V, MMAL_ENCODING_MP4V, 0, 0},
  77. {VC_CONTAINER_CODEC_MP2V, MMAL_ENCODING_MP2V, 0, 0},
  78. {VC_CONTAINER_CODEC_MP1V, MMAL_ENCODING_MP1V, 0, 0},
  79. {VC_CONTAINER_CODEC_WMV3, MMAL_ENCODING_WMV3, 0, 0},
  80. {VC_CONTAINER_CODEC_WMV2, MMAL_ENCODING_WMV2, 0, 0},
  81. {VC_CONTAINER_CODEC_WMV1, MMAL_ENCODING_WMV1, 0, 0},
  82. {VC_CONTAINER_CODEC_WVC1, MMAL_ENCODING_WVC1, 0, 0},
  83. {VC_CONTAINER_CODEC_VP6, MMAL_ENCODING_VP6, 0, 0},
  84. {VC_CONTAINER_CODEC_VP7, MMAL_ENCODING_VP7, 0, 0},
  85. {VC_CONTAINER_CODEC_VP8, MMAL_ENCODING_VP8, 0, 0},
  86. {VC_CONTAINER_CODEC_THEORA, MMAL_ENCODING_THEORA, 0, 0},
  87. {VC_CONTAINER_CODEC_SPARK, MMAL_ENCODING_SPARK, 0, 0},
  88. {VC_CONTAINER_CODEC_GIF, MMAL_ENCODING_GIF, 0, 0},
  89. {VC_CONTAINER_CODEC_JPEG, MMAL_ENCODING_JPEG, 0, 0},
  90. {VC_CONTAINER_CODEC_PNG, MMAL_ENCODING_PNG, 0, 0},
  91. {VC_CONTAINER_CODEC_PPM, MMAL_ENCODING_PPM, 0, 0},
  92. {VC_CONTAINER_CODEC_TGA, MMAL_ENCODING_TGA, 0, 0},
  93. {VC_CONTAINER_CODEC_BMP, MMAL_ENCODING_BMP, 0, 0},
  94. {VC_CONTAINER_CODEC_PCM_SIGNED_BE, MMAL_ENCODING_PCM_SIGNED_BE, 0, 0},
  95. {VC_CONTAINER_CODEC_PCM_UNSIGNED_BE,MMAL_ENCODING_PCM_UNSIGNED_BE, 0, 0},
  96. {VC_CONTAINER_CODEC_PCM_SIGNED_LE, MMAL_ENCODING_PCM_SIGNED_LE, 0, 0},
  97. {VC_CONTAINER_CODEC_PCM_UNSIGNED_LE,MMAL_ENCODING_PCM_UNSIGNED_LE, 0, 0},
  98. {VC_CONTAINER_CODEC_PCM_FLOAT_BE, MMAL_ENCODING_PCM_FLOAT_BE, 0, 0},
  99. {VC_CONTAINER_CODEC_PCM_FLOAT_LE, MMAL_ENCODING_PCM_FLOAT_LE, 0, 0},
  100. {VC_CONTAINER_CODEC_MPGA, MMAL_ENCODING_MPGA, 0, 0},
  101. {VC_CONTAINER_CODEC_MP4A, MMAL_ENCODING_MP4A, 0, 0},
  102. {VC_CONTAINER_CODEC_ALAW, MMAL_ENCODING_ALAW, 0, 0},
  103. {VC_CONTAINER_CODEC_MULAW, MMAL_ENCODING_MULAW, 0, 0},
  104. {VC_CONTAINER_CODEC_ADPCM_MS, MMAL_ENCODING_ADPCM_MS, 0, 0},
  105. {VC_CONTAINER_CODEC_ADPCM_IMA_MS, MMAL_ENCODING_ADPCM_IMA_MS, 0, 0},
  106. {VC_CONTAINER_CODEC_ADPCM_SWF, MMAL_ENCODING_ADPCM_SWF, 0, 0},
  107. {VC_CONTAINER_CODEC_WMA1, MMAL_ENCODING_WMA1, 0, 0},
  108. {VC_CONTAINER_CODEC_WMA2, MMAL_ENCODING_WMA2, 0, 0},
  109. {VC_CONTAINER_CODEC_WMAP, MMAL_ENCODING_WMAP, 0, 0},
  110. {VC_CONTAINER_CODEC_WMAL, MMAL_ENCODING_WMAL, 0, 0},
  111. {VC_CONTAINER_CODEC_WMAV, MMAL_ENCODING_WMAV, 0, 0},
  112. {VC_CONTAINER_CODEC_AMRNB, MMAL_ENCODING_AMRNB, 0, 0},
  113. {VC_CONTAINER_CODEC_AMRWB, MMAL_ENCODING_AMRWB, 0, 0},
  114. {VC_CONTAINER_CODEC_AMRWBP, MMAL_ENCODING_AMRWBP, 0, 0},
  115. {VC_CONTAINER_CODEC_AC3, MMAL_ENCODING_AC3, 0, 0},
  116. {VC_CONTAINER_CODEC_EAC3, MMAL_ENCODING_EAC3, 0, 0},
  117. {VC_CONTAINER_CODEC_DTS, MMAL_ENCODING_DTS, 0, 0},
  118. {VC_CONTAINER_CODEC_MLP, MMAL_ENCODING_MLP, 0, 0},
  119. {VC_CONTAINER_CODEC_FLAC, MMAL_ENCODING_FLAC, 0, 0},
  120. {VC_CONTAINER_CODEC_VORBIS, MMAL_ENCODING_VORBIS, 0, 0},
  121. {VC_CONTAINER_CODEC_SPEEX, MMAL_ENCODING_SPEEX, 0, 0},
  122. {VC_CONTAINER_CODEC_ATRAC3, MMAL_ENCODING_ATRAC3, 0, 0},
  123. {VC_CONTAINER_CODEC_ATRACX, MMAL_ENCODING_ATRACX, 0, 0},
  124. {VC_CONTAINER_CODEC_ATRACL, MMAL_ENCODING_ATRACL, 0, 0},
  125. {VC_CONTAINER_CODEC_MIDI, MMAL_ENCODING_MIDI, 0, 0},
  126. {VC_CONTAINER_CODEC_EVRC, MMAL_ENCODING_EVRC, 0, 0},
  127. {VC_CONTAINER_CODEC_NELLYMOSER, MMAL_ENCODING_NELLYMOSER, 0, 0},
  128. {VC_CONTAINER_CODEC_QCELP, MMAL_ENCODING_QCELP, 0, 0},
  129. {VC_CONTAINER_CODEC_UNKNOWN, MMAL_ENCODING_UNKNOWN, 0, 0}
  130. };
  131. static MMAL_FOURCC_T container_to_mmal_encoding(VC_CONTAINER_FOURCC_T codec)
  132. {
  133. unsigned int i;
  134. for(i = 0; encoding_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++)
  135. if(encoding_table[i].codec == codec)
  136. break;
  137. return encoding_table[i].encoding;
  138. }
  139. static VC_CONTAINER_FOURCC_T mmal_to_container_encoding(uint32_t encoding)
  140. {
  141. unsigned int i;
  142. for(i = 0; encoding_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++)
  143. if(encoding_table[i].encoding == encoding)
  144. break;
  145. return encoding_table[i].codec;
  146. }
  147. static MMAL_FOURCC_T container_to_mmal_variant(VC_CONTAINER_FOURCC_T codec,
  148. VC_CONTAINER_FOURCC_T codec_variant)
  149. {
  150. unsigned int i;
  151. for(i = 0; encoding_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++)
  152. if(encoding_table[i].codec == codec &&
  153. encoding_table[i].codec_variant == codec_variant)
  154. break;
  155. return encoding_table[i].encoding_variant;
  156. }
  157. static VC_CONTAINER_FOURCC_T mmal_to_container_variant(MMAL_FOURCC_T encoding,
  158. MMAL_FOURCC_T encoding_variant)
  159. {
  160. unsigned int i;
  161. for(i = 0; encoding_table[i].codec != VC_CONTAINER_CODEC_UNKNOWN; i++)
  162. if(encoding_table[i].encoding == encoding &&
  163. encoding_table[i].encoding_variant == encoding_variant)
  164. break;
  165. return encoding_table[i].codec_variant;
  166. }
  167. /*****************************************************************************/
  168. static struct {
  169. VC_CONTAINER_ES_TYPE_T container_type;
  170. MMAL_ES_TYPE_T type;
  171. } es_type_table[] =
  172. {
  173. {VC_CONTAINER_ES_TYPE_VIDEO, MMAL_ES_TYPE_VIDEO},
  174. {VC_CONTAINER_ES_TYPE_AUDIO, MMAL_ES_TYPE_AUDIO},
  175. {VC_CONTAINER_ES_TYPE_SUBPICTURE, MMAL_ES_TYPE_SUBPICTURE},
  176. {VC_CONTAINER_ES_TYPE_UNKNOWN, MMAL_ES_TYPE_UNKNOWN}
  177. };
  178. static MMAL_ES_TYPE_T container_to_mmal_es_type(VC_CONTAINER_ES_TYPE_T type)
  179. {
  180. unsigned int i;
  181. for(i = 0; es_type_table[i].container_type != VC_CONTAINER_ES_TYPE_UNKNOWN; i++)
  182. if(es_type_table[i].container_type == type)
  183. break;
  184. return es_type_table[i].type;
  185. }
  186. static VC_CONTAINER_ES_TYPE_T mmal_to_container_es_type(MMAL_ES_TYPE_T type)
  187. {
  188. unsigned int i;
  189. for(i = 0; es_type_table[i].container_type != VC_CONTAINER_ES_TYPE_UNKNOWN; i++)
  190. if(es_type_table[i].type == type)
  191. break;
  192. return es_type_table[i].container_type;
  193. }
  194. static MMAL_STATUS_T container_map_to_mmal_status(VC_CONTAINER_STATUS_T cstatus)
  195. {
  196. switch (cstatus)
  197. {
  198. case VC_CONTAINER_SUCCESS: return MMAL_SUCCESS;
  199. case VC_CONTAINER_ERROR_CORRUPTED: return MMAL_ECORRUPT;
  200. case VC_CONTAINER_ERROR_OUT_OF_MEMORY: return MMAL_ENOMEM;
  201. case VC_CONTAINER_ERROR_OUT_OF_RESOURCES: return MMAL_ENOSPC;
  202. case VC_CONTAINER_ERROR_NOT_READY: return MMAL_ENOTREADY;
  203. case VC_CONTAINER_ERROR_NOT_FOUND: return MMAL_ENOENT;
  204. case VC_CONTAINER_ERROR_URI_NOT_FOUND: return MMAL_ENOENT;
  205. default: return MMAL_EINVAL;
  206. }
  207. }
  208. static MMAL_STATUS_T container_to_mmal_format(MMAL_ES_FORMAT_T *format,
  209. VC_CONTAINER_ES_FORMAT_T *container_format)
  210. {
  211. format->type = container_to_mmal_es_type(container_format->es_type);
  212. if(format->type == MMAL_ES_TYPE_UNKNOWN)
  213. return MMAL_EINVAL;
  214. format->encoding = container_to_mmal_encoding(container_format->codec);
  215. format->encoding_variant = container_to_mmal_variant(container_format->codec, container_format->codec_variant);
  216. format->bitrate = container_format->bitrate;
  217. format->flags = (container_format->flags & VC_CONTAINER_ES_FORMAT_FLAG_FRAMED) ?
  218. MMAL_ES_FORMAT_FLAG_FRAMED : 0;
  219. memset(format->es, 0, sizeof(*format->es));
  220. switch(format->type)
  221. {
  222. case MMAL_ES_TYPE_VIDEO:
  223. format->es->video.width = container_format->type->video.width;
  224. format->es->video.height = container_format->type->video.height;
  225. format->es->video.crop.width = container_format->type->video.visible_width;
  226. format->es->video.crop.height = container_format->type->video.visible_height;
  227. format->es->video.frame_rate.num = container_format->type->video.frame_rate_num;
  228. format->es->video.frame_rate.den = container_format->type->video.frame_rate_den;
  229. format->es->video.par.num = container_format->type->video.par_num;
  230. format->es->video.par.den = container_format->type->video.par_den;
  231. break;
  232. case MMAL_ES_TYPE_AUDIO:
  233. format->es->audio.channels = container_format->type->audio.channels;
  234. format->es->audio.sample_rate = container_format->type->audio.sample_rate;
  235. format->es->audio.bits_per_sample = container_format->type->audio.bits_per_sample;
  236. format->es->audio.block_align = container_format->type->audio.block_align;
  237. break;
  238. default:
  239. LOG_ERROR("format es type not handled (%i)", (int)format->type);
  240. break;
  241. }
  242. if(container_format->extradata_size)
  243. {
  244. MMAL_STATUS_T status = mmal_format_extradata_alloc(format, container_format->extradata_size);
  245. if(status != MMAL_SUCCESS)
  246. {
  247. LOG_ERROR("couldn't allocate extradata");
  248. return status;
  249. }
  250. format->extradata_size = container_format->extradata_size;
  251. memcpy(format->extradata, container_format->extradata, format->extradata_size);
  252. }
  253. return MMAL_SUCCESS;
  254. }
  255. static MMAL_STATUS_T mmal_to_container_format(VC_CONTAINER_ES_FORMAT_T *container_format,
  256. MMAL_ES_FORMAT_T *format)
  257. {
  258. container_format->es_type = mmal_to_container_es_type(format->type);
  259. if(container_format->es_type == VC_CONTAINER_ES_TYPE_UNKNOWN)
  260. return MMAL_EINVAL;
  261. container_format->codec = mmal_to_container_encoding(format->encoding);
  262. container_format->codec_variant = mmal_to_container_variant(format->encoding, format->encoding_variant);
  263. container_format->bitrate = format->bitrate;
  264. container_format->flags = 0;
  265. if(format->flags & MMAL_ES_FORMAT_FLAG_FRAMED)
  266. container_format->flags |= VC_CONTAINER_ES_FORMAT_FLAG_FRAMED;
  267. memset(container_format->type, 0, sizeof(*container_format->type));
  268. /* Auto-detect H264 AVC1 variant */
  269. if(format->encoding == MMAL_ENCODING_H264 && !format->encoding_variant &&
  270. format->extradata_size >= 5 && *format->extradata == 1)
  271. container_format->codec_variant = VC_CONTAINER_VARIANT_H264_AVC1;
  272. switch(format->type)
  273. {
  274. case MMAL_ES_TYPE_VIDEO:
  275. container_format->type->video.width = format->es->video.width;
  276. container_format->type->video.height = format->es->video.height;
  277. container_format->type->video.frame_rate_num = format->es->video.frame_rate.num;
  278. container_format->type->video.frame_rate_den = format->es->video.frame_rate.den;
  279. container_format->type->video.par_num = format->es->video.par.num;
  280. container_format->type->video.par_den = format->es->video.par.den;
  281. break;
  282. case MMAL_ES_TYPE_AUDIO:
  283. container_format->type->audio.channels = format->es->audio.channels;
  284. container_format->type->audio.sample_rate = format->es->audio.sample_rate;
  285. container_format->type->audio.bits_per_sample = format->es->audio.bits_per_sample;
  286. container_format->type->audio.block_align = format->es->audio.block_align;
  287. break;
  288. default:
  289. LOG_ERROR("format es type not handled (%i)", (int)format->type);
  290. break;
  291. }
  292. container_format->extradata_size = format->extradata_size;
  293. container_format->extradata = format->extradata;
  294. return MMAL_SUCCESS;
  295. }
  296. /*****************************************************************************/
  297. static void reader_do_processing(MMAL_COMPONENT_T *component)
  298. {
  299. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  300. MMAL_BUFFER_HEADER_T *buffer;
  301. VC_CONTAINER_STATUS_T cstatus;
  302. VC_CONTAINER_PACKET_T packet;
  303. MMAL_STATUS_T status;
  304. unsigned int i;
  305. memset(&packet, 0, sizeof(packet));
  306. while(1)
  307. {
  308. cstatus = vc_container_read(module->container, &packet, VC_CONTAINER_READ_FLAG_INFO);
  309. if(cstatus == VC_CONTAINER_ERROR_CONTINUE)
  310. continue;
  311. if(cstatus != VC_CONTAINER_SUCCESS)
  312. {
  313. LOG_DEBUG("READ EOF (%i)", cstatus);
  314. break;
  315. }
  316. if (!module->packet_logged)
  317. LOG_DEBUG("packet info: track %i, size %i/%i, pts %"PRId64"%s, dts %"PRId64"%s, flags %x%s",
  318. packet.track, packet.size, packet.frame_size,
  319. packet.pts == VC_CONTAINER_TIME_UNKNOWN ? 0 : packet.pts,
  320. packet.pts == VC_CONTAINER_TIME_UNKNOWN ? ":unknown" : "",
  321. packet.dts == VC_CONTAINER_TIME_UNKNOWN ? 0 : packet.dts,
  322. packet.dts == VC_CONTAINER_TIME_UNKNOWN ? ":unknown" : "",
  323. packet.flags, (packet.flags & VC_CONTAINER_PACKET_FLAG_KEYFRAME) ? " (keyframe)" : "");
  324. /* Find the port corresponding to that track */
  325. for(i = 0; i < module->ports; i++)
  326. if(component->output[i]->priv->module->track == packet.track)
  327. break;
  328. if(i == module->ports)
  329. {
  330. vc_container_read(module->container, 0, VC_CONTAINER_READ_FLAG_SKIP);
  331. continue;
  332. }
  333. /* Get a buffer from this port */
  334. buffer = mmal_queue_get(component->output[i]->priv->module->queue);
  335. if(!buffer)
  336. {
  337. module->packet_logged = 1;
  338. break; /* Try again next time */
  339. }
  340. module->packet_logged = 0;
  341. if(component->output[i]->priv->module->flush)
  342. {
  343. buffer->length = 0;
  344. component->output[i]->priv->module->flush = MMAL_FALSE;
  345. }
  346. mmal_buffer_header_mem_lock(buffer);
  347. packet.data = buffer->data + buffer->length;
  348. packet.buffer_size = buffer->alloc_size - buffer->length;
  349. packet.size = 0;
  350. cstatus = vc_container_read(module->container, &packet, 0);
  351. mmal_buffer_header_mem_unlock(buffer);
  352. if(cstatus != VC_CONTAINER_SUCCESS)
  353. {
  354. LOG_DEBUG("TEST read status: %i", cstatus);
  355. mmal_queue_put_back(component->output[i]->priv->module->queue, buffer);
  356. break;
  357. }
  358. if(!buffer->length)
  359. {
  360. buffer->pts = packet.pts == VC_CONTAINER_TIME_UNKNOWN ? MMAL_TIME_UNKNOWN : packet.pts;
  361. buffer->dts = packet.dts == VC_CONTAINER_TIME_UNKNOWN ? MMAL_TIME_UNKNOWN : packet.dts;
  362. buffer->flags = 0;
  363. if(packet.flags & VC_CONTAINER_PACKET_FLAG_KEYFRAME)
  364. buffer->flags |= MMAL_BUFFER_HEADER_FLAG_KEYFRAME;
  365. if(packet.flags & VC_CONTAINER_PACKET_FLAG_FRAME_START)
  366. buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_START;
  367. }
  368. if(packet.flags & VC_CONTAINER_PACKET_FLAG_FRAME_END)
  369. buffer->flags |= MMAL_BUFFER_HEADER_FLAG_FRAME_END;
  370. #ifdef VC_CONTAINER_PACKET_FLAG_CONFIG
  371. if(packet.flags & VC_CONTAINER_PACKET_FLAG_CONFIG)
  372. buffer->flags |= MMAL_BUFFER_HEADER_FLAG_CONFIG;
  373. #endif
  374. buffer->length += packet.size;
  375. if((component->output[i]->format->flags & MMAL_ES_FORMAT_FLAG_FRAMED) &&
  376. buffer->length != buffer->alloc_size &&
  377. !(buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END))
  378. {
  379. mmal_queue_put_back(component->output[i]->priv->module->queue, buffer);
  380. continue;
  381. }
  382. /* Send buffer back */
  383. mmal_port_buffer_header_callback(component->output[i], buffer);
  384. }
  385. if(cstatus == VC_CONTAINER_ERROR_EOS)
  386. {
  387. /* Send an empty EOS buffer for each port */
  388. for(i = 0; i < component->output_num; i++)
  389. {
  390. MMAL_PORT_T *port = component->output[i];
  391. if(!port->is_enabled)
  392. continue;
  393. if(port->priv->module->eos)
  394. continue;
  395. /* Get a buffer from this port */
  396. buffer = mmal_queue_get(port->priv->module->queue);
  397. if(!buffer)
  398. continue; /* Try again next time */
  399. buffer->length = 0;
  400. buffer->pts = buffer->dts = MMAL_TIME_UNKNOWN;
  401. buffer->flags = MMAL_BUFFER_HEADER_FLAG_EOS;
  402. /* Send buffer back */
  403. port->priv->module->eos = 1;
  404. mmal_port_buffer_header_callback(port, buffer);
  405. }
  406. }
  407. else if(cstatus != VC_CONTAINER_SUCCESS && !module->error)
  408. {
  409. status = mmal_event_error_send(component, container_map_to_mmal_status(cstatus));
  410. if (status != MMAL_SUCCESS)
  411. {
  412. LOG_ERROR("unable to send an error event buffer (%i)", (int)status);
  413. return;
  414. }
  415. module->error = 1;
  416. }
  417. return;
  418. }
  419. /*****************************************************************************/
  420. static void writer_do_processing(MMAL_COMPONENT_T *component)
  421. {
  422. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  423. VC_CONTAINER_STATUS_T cstatus;
  424. MMAL_PORT_MODULE_T *port_module;
  425. MMAL_PORT_T *port;
  426. MMAL_STATUS_T status;
  427. MMAL_BOOL_T eos;
  428. int64_t timestamp, timestamp_current;
  429. MMAL_BUFFER_HEADER_T *buffer;
  430. VC_CONTAINER_PACKET_T packet;
  431. unsigned int i, index;
  432. if(module->error)
  433. return;
  434. /* Select the next port to read from based on earliest timestamp. Buffers without
  435. * timestamps will end-up being prioritised. */
  436. for(i = 0, index = module->port_last_used, port = 0, timestamp = INT64_C(0);
  437. i < component->input_num; i++, index++)
  438. {
  439. if(index == component->input_num)
  440. index = 0;
  441. if(!component->input[index]->is_enabled)
  442. continue;
  443. buffer = mmal_queue_get(component->input[index]->priv->module->queue);
  444. if(!buffer)
  445. continue;
  446. timestamp_current = buffer->dts;
  447. if (timestamp_current == MMAL_TIME_UNKNOWN)
  448. timestamp_current = buffer->pts;
  449. if(!port)
  450. timestamp = timestamp_current;
  451. if(timestamp_current <= timestamp)
  452. {
  453. port = component->input[index];
  454. timestamp = timestamp_current;
  455. module->port_last_used = index;
  456. }
  457. mmal_queue_put_back(component->input[index]->priv->module->queue, buffer);
  458. }
  459. /* If a port is currently writing a frame then we override the decision to avoid
  460. * splitting frames */
  461. if(module->port_writing_frame && module->port_writing_frame - 1 < component->input_num &&
  462. component->input[module->port_writing_frame-1]->is_enabled)
  463. port = component->input[module->port_writing_frame-1];
  464. if(!port)
  465. return; /* nothing to write */
  466. port_module = port->priv->module;
  467. /* Get a buffer from this port */
  468. buffer = mmal_queue_get(port_module->queue);
  469. if(!buffer)
  470. return; /* nothing to write */
  471. mmal_buffer_header_mem_lock(buffer);
  472. memset(&packet, 0, sizeof(packet));
  473. packet.track = port_module->track;
  474. packet.size = buffer->length;
  475. packet.data = buffer->data + buffer->offset;
  476. packet.pts = buffer->pts == MMAL_TIME_UNKNOWN ? VC_CONTAINER_TIME_UNKNOWN : buffer->pts;
  477. packet.dts = buffer->dts == MMAL_TIME_UNKNOWN ? VC_CONTAINER_TIME_UNKNOWN : buffer->dts;
  478. if(buffer->flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME)
  479. packet.flags |= VC_CONTAINER_PACKET_FLAG_KEYFRAME;
  480. if(buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_START)
  481. packet.flags |= VC_CONTAINER_PACKET_FLAG_FRAME_START;
  482. if(buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  483. packet.flags |= VC_CONTAINER_PACKET_FLAG_FRAME_END;
  484. eos = buffer->flags & MMAL_BUFFER_HEADER_FLAG_EOS;
  485. if ((packet.flags & VC_CONTAINER_PACKET_FLAG_FRAME) == VC_CONTAINER_PACKET_FLAG_FRAME)
  486. packet.frame_size = packet.size;
  487. else
  488. packet.frame_size = 0;
  489. module->port_writing_frame = port->index + 1;
  490. if((buffer->flags & MMAL_BUFFER_HEADER_FLAG_FRAME_END) ||
  491. !(port->format->flags & MMAL_ES_FORMAT_FLAG_FRAMED))
  492. module->port_writing_frame = 0;
  493. LOG_DEBUG("packet info: track %i, size %i/%i, pts %"PRId64", flags %x%s",
  494. packet.track, packet.size, packet.frame_size, packet.pts,
  495. packet.flags, (packet.flags & VC_CONTAINER_PACKET_FLAG_KEYFRAME) ? " (keyframe)" : "");
  496. cstatus = vc_container_write(module->container, &packet);
  497. mmal_buffer_header_mem_unlock(buffer);
  498. /* Send buffer back */
  499. buffer->length = 0;
  500. mmal_port_buffer_header_callback(port, buffer);
  501. /* Check for errors */
  502. if(cstatus != VC_CONTAINER_SUCCESS)
  503. {
  504. LOG_ERROR("write failed (%i)", (int)cstatus);
  505. status = mmal_event_error_send(component, container_map_to_mmal_status(cstatus));
  506. if (status != MMAL_SUCCESS)
  507. {
  508. LOG_ERROR("unable to send an error event buffer (%i)", (int)status);
  509. return;
  510. }
  511. module->error = 1;
  512. return;
  513. }
  514. /* Generate EOS events */
  515. if(eos)
  516. {
  517. MMAL_EVENT_END_OF_STREAM_T *event;
  518. status = mmal_port_event_get(component->control, &buffer, MMAL_EVENT_EOS);
  519. if (status != MMAL_SUCCESS)
  520. {
  521. LOG_ERROR("unable to get an event buffer");
  522. return;
  523. }
  524. buffer->length = sizeof(*event);
  525. event = (MMAL_EVENT_END_OF_STREAM_T *)buffer->data;
  526. event->port_type = port->type;
  527. event->port_index = port->index;
  528. mmal_port_event_send(component->control, buffer);
  529. }
  530. }
  531. /** Destroy a previously created component */
  532. static MMAL_STATUS_T container_component_destroy(MMAL_COMPONENT_T *component)
  533. {
  534. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  535. unsigned int i;
  536. if(module->container)
  537. vc_container_close(module->container);
  538. for(i = 0; i < component->input_num; i++)
  539. {
  540. if(component->input[i]->priv->module->queue)
  541. mmal_queue_destroy(component->input[i]->priv->module->queue);
  542. if(component->input[i]->priv->module->format)
  543. vc_container_format_delete(component->input[i]->priv->module->format);
  544. }
  545. if(component->input_num)
  546. mmal_ports_free(component->input, component->input_num);
  547. for(i = 0; i < component->output_num; i++)
  548. if(component->output[i]->priv->module->queue)
  549. mmal_queue_destroy(component->output[i]->priv->module->queue);
  550. if(component->output_num)
  551. mmal_ports_free(component->output, component->output_num);
  552. vcos_free(module);
  553. return MMAL_SUCCESS;
  554. }
  555. /** Enable processing on a port */
  556. static MMAL_STATUS_T container_port_enable(MMAL_PORT_T *port, MMAL_PORT_BH_CB_T cb)
  557. {
  558. MMAL_COMPONENT_T *component = port->component;
  559. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  560. MMAL_PORT_MODULE_T *port_module = port->priv->module;
  561. MMAL_PARAM_UNUSED(cb);
  562. if(!module->container)
  563. return MMAL_EINVAL;
  564. if(module->writer)
  565. {
  566. VC_CONTAINER_STATUS_T cstatus;
  567. port_module->track = module->container->tracks_num;
  568. cstatus = vc_container_control(module->container, VC_CONTAINER_CONTROL_TRACK_ADD,
  569. port_module->format);
  570. if(cstatus != VC_CONTAINER_SUCCESS)
  571. {
  572. LOG_ERROR("error adding track %4.4s (%i)", (char *)&port->format->encoding, (int)cstatus);
  573. return container_map_to_mmal_status(cstatus);
  574. }
  575. }
  576. if(port_module->track >= module->container->tracks_num)
  577. {
  578. LOG_ERROR("error 1 adding track %4.4s (%i/%i)", (char *)&port->format->encoding, port_module->track, module->container->tracks_num);
  579. return MMAL_EINVAL;
  580. }
  581. module->container->tracks[port_module->track]->is_enabled = 1;
  582. return MMAL_SUCCESS;
  583. }
  584. /** Flush a port */
  585. static MMAL_STATUS_T container_port_flush(MMAL_PORT_T *port)
  586. {
  587. MMAL_PORT_MODULE_T *port_module = port->priv->module;
  588. MMAL_BUFFER_HEADER_T *buffer;
  589. /* Flush buffers that our component is holding on to.
  590. * If the reading thread is holding onto a buffer it will send it back ASAP as well
  591. * so no need to care about that. */
  592. buffer = mmal_queue_get(port_module->queue);
  593. while(buffer)
  594. {
  595. buffer->length = 0;
  596. mmal_port_buffer_header_callback(port, buffer);
  597. buffer = mmal_queue_get(port_module->queue);
  598. }
  599. return MMAL_SUCCESS;
  600. }
  601. /** Disable processing on a port */
  602. static MMAL_STATUS_T container_port_disable(MMAL_PORT_T *port)
  603. {
  604. MMAL_COMPONENT_T *component = port->component;
  605. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  606. unsigned int track = port->priv->module->track;
  607. MMAL_STATUS_T status;
  608. if(!module->container || track >= module->container->tracks_num)
  609. return MMAL_EINVAL;
  610. /* Actions are prevented from running at that point so a flush
  611. * will return all buffers. */
  612. status = container_port_flush(port);
  613. if(status != MMAL_SUCCESS)
  614. return status;
  615. module->container->tracks[track]->is_enabled = 0;
  616. return MMAL_SUCCESS;
  617. }
  618. /** Send a buffer header to a port */
  619. static MMAL_STATUS_T container_port_send(MMAL_PORT_T *port, MMAL_BUFFER_HEADER_T *buffer)
  620. {
  621. mmal_queue_put(port->priv->module->queue, buffer);
  622. mmal_component_action_trigger(port->component);
  623. return MMAL_SUCCESS;
  624. }
  625. /** Set format on a port */
  626. static MMAL_STATUS_T container_port_set_format(MMAL_PORT_T *port)
  627. {
  628. MMAL_COMPONENT_T *component = port->component;
  629. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  630. MMAL_STATUS_T status;
  631. if(!module->writer)
  632. return MMAL_EINVAL;
  633. /* Set format of the track */
  634. status = mmal_to_container_format(port->priv->module->format, port->format);
  635. if (status != MMAL_SUCCESS)
  636. return status;
  637. port->buffer_num_min = READER_MIN_BUFFER_NUM;
  638. port->buffer_num_recommended = READER_RECOMMENDED_BUFFER_NUM;
  639. port->buffer_size_min = READER_MIN_BUFFER_SIZE;
  640. port->buffer_size_recommended = READER_RECOMMENDED_BUFFER_SIZE;
  641. return MMAL_SUCCESS;
  642. }
  643. static MMAL_STATUS_T reader_container_open(MMAL_COMPONENT_T *component, const char *uri)
  644. {
  645. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  646. VC_CONTAINER_STATUS_T cstatus;
  647. VC_CONTAINER_T *container;
  648. unsigned int i, port, track;
  649. /* Open container */
  650. module->container = container =
  651. vc_container_open_reader(uri, &cstatus, 0, 0);
  652. if(!container)
  653. {
  654. LOG_ERROR("error opening file %s (%i)", uri, cstatus);
  655. return container_map_to_mmal_status(cstatus);
  656. }
  657. /* Disable all tracks */
  658. for(track = 0; track < container->tracks_num; track++)
  659. container->tracks[track]->is_enabled = 0;
  660. /* Fill-in the ports */
  661. for(i = 0, port = 0; i < component->output_num; i++)
  662. {
  663. VC_CONTAINER_ES_TYPE_T type = VC_CONTAINER_ES_TYPE_VIDEO;
  664. if(i == 1) type = VC_CONTAINER_ES_TYPE_AUDIO;
  665. if(i == 2) type = VC_CONTAINER_ES_TYPE_SUBPICTURE;
  666. /* Look for the first track with the specified type */
  667. for(track = 0; track < container->tracks_num; track++)
  668. if(container->tracks[track]->format->es_type == type)
  669. break;
  670. if(track == container->tracks_num)
  671. continue;
  672. if(container_to_mmal_encoding(container->tracks[track]->format->codec) == MMAL_ENCODING_UNKNOWN)
  673. continue;
  674. /* Set format of the port */
  675. if(container_to_mmal_format(component->output[port]->format,
  676. container->tracks[track]->format) != MMAL_SUCCESS)
  677. continue;
  678. component->output[port]->buffer_num_min = READER_MIN_BUFFER_NUM;
  679. component->output[port]->buffer_num_recommended = READER_RECOMMENDED_BUFFER_NUM;
  680. component->output[port]->buffer_size_min = READER_MIN_BUFFER_SIZE;
  681. component->output[port]->buffer_size_recommended = READER_RECOMMENDED_BUFFER_SIZE;
  682. component->output[port]->priv->module->track = track;
  683. /* We're done with this port */
  684. port++;
  685. }
  686. module->ports = port;
  687. /* Reset the left over ports */
  688. for(i = port; i < component->output_num; i++)
  689. {
  690. component->output[i]->format->type = MMAL_ES_TYPE_UNKNOWN;
  691. component->output[i]->format->encoding = MMAL_ENCODING_UNKNOWN;
  692. }
  693. return MMAL_SUCCESS;
  694. }
  695. static MMAL_STATUS_T reader_container_seek(MMAL_COMPONENT_T *component, const MMAL_PARAMETER_SEEK_T *seek)
  696. {
  697. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  698. VC_CONTAINER_SEEK_FLAGS_T flags = 0;
  699. int64_t offset = seek->offset;
  700. VC_CONTAINER_STATUS_T cstatus;
  701. unsigned int i;
  702. if(seek->flags & MMAL_PARAM_SEEK_FLAG_PRECISE)
  703. flags |= VC_CONTAINER_SEEK_FLAG_PRECISE;
  704. if(seek->flags & MMAL_PARAM_SEEK_FLAG_FORWARD)
  705. flags |= VC_CONTAINER_SEEK_FLAG_FORWARD;
  706. mmal_component_action_lock(component);
  707. for(i = 0; i < component->output_num; i++)
  708. {
  709. component->output[i]->priv->module->eos = MMAL_FALSE;
  710. component->output[i]->priv->module->flush = MMAL_TRUE;
  711. }
  712. cstatus = vc_container_seek( module->container, &offset, VC_CONTAINER_SEEK_MODE_TIME, flags);
  713. mmal_component_action_unlock(component);
  714. return container_map_to_mmal_status(cstatus);
  715. }
  716. static MMAL_STATUS_T reader_parameter_set(MMAL_PORT_T *port, const MMAL_PARAMETER_HEADER_T *param)
  717. {
  718. MMAL_COMPONENT_T *component = port->component;
  719. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  720. switch(param->id)
  721. {
  722. case MMAL_PARAMETER_URI:
  723. if(module->container)
  724. return MMAL_EINVAL;
  725. memset(module->uri, 0, sizeof(module->uri));
  726. strncpy(module->uri, ((const MMAL_PARAMETER_STRING_T *)param)->str, sizeof(module->uri)-1 );
  727. return reader_container_open(component, module->uri);
  728. case MMAL_PARAMETER_SEEK:
  729. if(!module->container || param->size < sizeof(MMAL_PARAMETER_SEEK_T))
  730. return MMAL_EINVAL;
  731. return reader_container_seek(component, (const MMAL_PARAMETER_SEEK_T *)param);
  732. default:
  733. return MMAL_ENOSYS;
  734. }
  735. return MMAL_SUCCESS;
  736. }
  737. /** Create an instance of a component */
  738. static MMAL_STATUS_T mmal_component_create_reader(const char *name, MMAL_COMPONENT_T *component)
  739. {
  740. MMAL_COMPONENT_MODULE_T *module;
  741. unsigned int outputs_num, i;
  742. MMAL_STATUS_T status = MMAL_ENOMEM;
  743. MMAL_PARAM_UNUSED(name);
  744. /* Allocate the context for our module */
  745. component->priv->module = module = vcos_malloc(sizeof(*module), "mmal module");
  746. if (!module)
  747. return MMAL_ENOMEM;
  748. memset(module, 0, sizeof(*module));
  749. component->priv->pf_destroy = container_component_destroy;
  750. /* Create 3 tracks for now (audio/video/subpicture).
  751. * FIXME: ideally we should create 1 track per elementary stream. */
  752. outputs_num = 3;
  753. /* Now the component on reader has been created, we can allocate
  754. * the ports for this component */
  755. component->output = mmal_ports_alloc(component, outputs_num, MMAL_PORT_TYPE_OUTPUT,
  756. sizeof(MMAL_PORT_MODULE_T));
  757. if(!component->output)
  758. goto error;
  759. component->output_num = outputs_num;
  760. for(i = 0; i < outputs_num; i++)
  761. {
  762. component->output[i]->priv->pf_enable = container_port_enable;
  763. component->output[i]->priv->pf_disable = container_port_disable;
  764. component->output[i]->priv->pf_flush = container_port_flush;
  765. component->output[i]->priv->pf_send = container_port_send;
  766. component->output[i]->priv->module->queue = mmal_queue_create();
  767. if(!component->output[i]->priv->module->queue)
  768. goto error;
  769. }
  770. component->control->priv->pf_parameter_set = reader_parameter_set;
  771. status = mmal_component_action_register(component, reader_do_processing);
  772. if (status != MMAL_SUCCESS)
  773. goto error;
  774. return MMAL_SUCCESS;
  775. error:
  776. container_component_destroy(component);
  777. return status;
  778. }
  779. static MMAL_STATUS_T writer_parameter_set(MMAL_PORT_T *port, const MMAL_PARAMETER_HEADER_T *param)
  780. {
  781. MMAL_COMPONENT_T *component = port->component;
  782. MMAL_COMPONENT_MODULE_T *module = component->priv->module;
  783. VC_CONTAINER_STATUS_T cstatus;
  784. switch(param->id)
  785. {
  786. case MMAL_PARAMETER_URI:
  787. if(module->container)
  788. return MMAL_EINVAL;
  789. memset(module->uri, 0, sizeof(module->uri));
  790. strncpy(module->uri, ((const MMAL_PARAMETER_URI_T *)param)->uri, sizeof(module->uri)-1 );
  791. /* Open container */
  792. module->container = vc_container_open_writer(module->uri, &cstatus, 0, 0);
  793. if(!module->container)
  794. {
  795. LOG_ERROR("error opening file %s (%i)", module->uri, cstatus);
  796. return container_map_to_mmal_status(cstatus);
  797. }
  798. return MMAL_SUCCESS;
  799. default:
  800. return MMAL_ENOSYS;
  801. }
  802. return MMAL_SUCCESS;
  803. }
  804. /** Create an instance of a component */
  805. static MMAL_STATUS_T mmal_component_create_writer(const char *name, MMAL_COMPONENT_T *component)
  806. {
  807. MMAL_COMPONENT_MODULE_T *module;
  808. MMAL_STATUS_T status = MMAL_ENOMEM;
  809. unsigned int i;
  810. MMAL_PARAM_UNUSED(name);
  811. /* Allocate the context for our module */
  812. component->priv->module = module = vcos_malloc(sizeof(*module), "mmal module");
  813. if (!module)
  814. return MMAL_ENOMEM;
  815. memset(module, 0, sizeof(*module));
  816. module->writer = 1;
  817. component->priv->pf_destroy = container_component_destroy;
  818. /* Now the component on reader has been created, we can allocate
  819. * the ports for this component */
  820. component->input = mmal_ports_alloc(component, WRITER_PORTS_NUM, MMAL_PORT_TYPE_INPUT,
  821. sizeof(MMAL_PORT_MODULE_T));
  822. if(!component->input)
  823. goto error;
  824. component->input_num = WRITER_PORTS_NUM;
  825. for(i = 0; i < component->input_num; i++)
  826. {
  827. component->input[i]->priv->pf_enable = container_port_enable;
  828. component->input[i]->priv->pf_disable = container_port_disable;
  829. component->input[i]->priv->pf_flush = container_port_flush;
  830. component->input[i]->priv->pf_send = container_port_send;
  831. component->input[i]->priv->pf_set_format = container_port_set_format;
  832. component->input[i]->priv->module->queue = mmal_queue_create();
  833. if(!component->input[i]->priv->module->queue)
  834. goto error;
  835. component->input[i]->priv->module->format = vc_container_format_create(0);
  836. if(!component->input[i]->priv->module->format)
  837. goto error;
  838. }
  839. component->control->priv->pf_parameter_set = writer_parameter_set;
  840. status = mmal_component_action_register(component, writer_do_processing);
  841. if (status != MMAL_SUCCESS)
  842. goto error;
  843. return MMAL_SUCCESS;
  844. error:
  845. container_component_destroy(component);
  846. return status;
  847. }
  848. MMAL_CONSTRUCTOR(mmal_register_component_container_reader);
  849. void mmal_register_component_container_reader(void)
  850. {
  851. mmal_component_supplier_register("container_reader", mmal_component_create_reader);
  852. }
  853. MMAL_CONSTRUCTOR(mmal_register_component_container_writer);
  854. void mmal_register_component_container_writer(void)
  855. {
  856. mmal_component_supplier_register("container_writer", mmal_component_create_writer);
  857. }