| 1 | /* |
| 2 | Copyright (c) 2012, Broadcom Europe Ltd |
| 3 | All rights reserved. |
| 4 | |
| 5 | Redistribution and use in source and binary forms, with or without |
| 6 | modification, are permitted provided that the following conditions are met: |
| 7 | * Redistributions of source code must retain the above copyright |
| 8 | notice, this list of conditions and the following disclaimer. |
| 9 | * Redistributions in binary form must reproduce the above copyright |
| 10 | notice, this list of conditions and the following disclaimer in the |
| 11 | documentation and/or other materials provided with the distribution. |
| 12 | * Neither the name of the copyright holder nor the |
| 13 | names of its contributors may be used to endorse or promote products |
| 14 | derived from this software without specific prior written permission. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
| 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | #ifndef VC_CONTAINERS_WRITER_UTILS_H |
| 28 | #define VC_CONTAINERS_WRITER_UTILS_H |
| 29 | |
| 30 | /** \file containers_writer_utils.h |
| 31 | * Helper functions and macros for container writers |
| 32 | */ |
| 33 | |
| 34 | #include "containers/containers.h" |
| 35 | #include "containers/containers_codecs.h" |
| 36 | #include "containers/core/containers_io_helpers.h" |
| 37 | |
| 38 | /***************************************************************************** |
| 39 | * Helper inline functions to write format specific structus to an i/o stream |
| 40 | *****************************************************************************/ |
| 41 | |
| 42 | STATIC_INLINE VC_CONTAINER_STATUS_T vc_container_write_waveformatex( VC_CONTAINER_T *p_ctx, |
| 43 | VC_CONTAINER_ES_FORMAT_T *format) |
| 44 | { |
| 45 | /* Write waveformatex structure */ |
| 46 | WRITE_U16(p_ctx, codec_to_waveformat(format->codec), "Codec ID" ); |
| 47 | WRITE_U16(p_ctx, format->type->audio.channels, "Number of Channels" ); |
| 48 | WRITE_U32(p_ctx, format->type->audio.sample_rate, "Samples per Second" ); |
| 49 | WRITE_U32(p_ctx, format->bitrate >> 3, "Average Number of Bytes Per Second" ); |
| 50 | WRITE_U16(p_ctx, format->type->audio.block_align, "Block Alignment" ); |
| 51 | WRITE_U16(p_ctx, format->type->audio.bits_per_sample, "Bits Per Sample" ); |
| 52 | WRITE_U16(p_ctx, format->extradata_size, "Codec Specific Data Size" ); |
| 53 | WRITE_BYTES(p_ctx, format->extradata, format->extradata_size); |
| 54 | |
| 55 | return STREAM_STATUS(p_ctx); |
| 56 | } |
| 57 | |
| 58 | STATIC_INLINE VC_CONTAINER_STATUS_T ( VC_CONTAINER_T *p_ctx, |
| 59 | VC_CONTAINER_ES_FORMAT_T *format) |
| 60 | { |
| 61 | VC_CONTAINER_FOURCC_T fourcc; |
| 62 | |
| 63 | /* Write bitmapinfoheader structure */ |
| 64 | WRITE_U32(p_ctx, 40, "Format Data Size" ); |
| 65 | WRITE_U32(p_ctx, format->type->video.width, "Image Width" ); |
| 66 | WRITE_U32(p_ctx, format->type->video.height, "Image Height" ); |
| 67 | WRITE_U16(p_ctx, 0, "Reserved" ); |
| 68 | WRITE_U16(p_ctx, 0, "Bits Per Pixel Count" ); |
| 69 | fourcc = codec_to_vfw_fourcc(format->codec); |
| 70 | WRITE_BYTES(p_ctx, (char *)&fourcc, 4); /* Compression ID */ |
| 71 | LOG_FORMAT(p_ctx, "Compression ID: %4.4s" , (char *)&fourcc); |
| 72 | WRITE_U32(p_ctx, 0, "Image Size" ); |
| 73 | WRITE_U32(p_ctx, 0, "Horizontal Pixels Per Meter" ); |
| 74 | WRITE_U32(p_ctx, 0, "Vertical Pixels Per Meter" ); |
| 75 | WRITE_U32(p_ctx, 0, "Colors Used Count" ); |
| 76 | WRITE_U32(p_ctx, 0, "Important Colors Count" ); |
| 77 | |
| 78 | WRITE_BYTES(p_ctx, format->extradata, format->extradata_size); |
| 79 | |
| 80 | return STREAM_STATUS(p_ctx); |
| 81 | } |
| 82 | |
| 83 | /* Helper functions to create and use extra i/o */ |
| 84 | typedef struct { |
| 85 | VC_CONTAINER_IO_T *; |
| 86 | unsigned int ; |
| 87 | bool ; |
| 88 | } ; |
| 89 | |
| 90 | VC_CONTAINER_STATUS_T (VC_CONTAINER_T *context, VC_CONTAINER_WRITER_EXTRAIO_T *null); |
| 91 | VC_CONTAINER_STATUS_T (VC_CONTAINER_T *context, VC_CONTAINER_WRITER_EXTRAIO_T *null); |
| 92 | VC_CONTAINER_STATUS_T (VC_CONTAINER_T *context, VC_CONTAINER_WRITER_EXTRAIO_T *null); |
| 93 | int64_t (VC_CONTAINER_T *context, VC_CONTAINER_WRITER_EXTRAIO_T *null); |
| 94 | int64_t (VC_CONTAINER_T *context, VC_CONTAINER_WRITER_EXTRAIO_T *null); |
| 95 | |
| 96 | #endif /* VC_CONTAINERS_WRITER_UTILS_H */ |
| 97 | |