| 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 | #include <stdlib.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include "containers/core/containers_private.h" |
| 31 | #include "containers/core/containers_io_helpers.h" |
| 32 | #include "containers/core/containers_utils.h" |
| 33 | #include "containers/core/containers_logging.h" |
| 34 | |
| 35 | /****************************************************************************** |
| 36 | Type definitions |
| 37 | ******************************************************************************/ |
| 38 | typedef struct VC_CONTAINER_MODULE_T |
| 39 | { |
| 40 | VC_CONTAINER_TRACK_T *track[2]; |
| 41 | |
| 42 | } VC_CONTAINER_MODULE_T; |
| 43 | |
| 44 | /****************************************************************************** |
| 45 | Function prototypes |
| 46 | ******************************************************************************/ |
| 47 | VC_CONTAINER_STATUS_T dummy_writer_open( VC_CONTAINER_T * ); |
| 48 | |
| 49 | /***************************************************************************** |
| 50 | Functions exported as part of the Container Module API |
| 51 | *****************************************************************************/ |
| 52 | static VC_CONTAINER_STATUS_T dummy_writer_close( VC_CONTAINER_T *p_ctx ) |
| 53 | { |
| 54 | VC_CONTAINER_MODULE_T *module = p_ctx->priv->module; |
| 55 | for(; p_ctx->tracks_num > 0; p_ctx->tracks_num--) |
| 56 | vc_container_free_track(p_ctx, p_ctx->tracks[p_ctx->tracks_num-1]); |
| 57 | free(module); |
| 58 | return VC_CONTAINER_SUCCESS; |
| 59 | } |
| 60 | |
| 61 | /*****************************************************************************/ |
| 62 | static VC_CONTAINER_STATUS_T dummy_writer_write( VC_CONTAINER_T *p_ctx, |
| 63 | VC_CONTAINER_PACKET_T *packet ) |
| 64 | { |
| 65 | VC_CONTAINER_PARAM_UNUSED(p_ctx); |
| 66 | VC_CONTAINER_PARAM_UNUSED(packet); |
| 67 | return VC_CONTAINER_SUCCESS; |
| 68 | } |
| 69 | |
| 70 | /*****************************************************************************/ |
| 71 | static VC_CONTAINER_STATUS_T dummy_writer_control( VC_CONTAINER_T *p_ctx, |
| 72 | VC_CONTAINER_CONTROL_T operation, va_list args ) |
| 73 | { |
| 74 | VC_CONTAINER_TRACK_T *track; |
| 75 | VC_CONTAINER_PARAM_UNUSED(args); |
| 76 | |
| 77 | switch(operation) |
| 78 | { |
| 79 | case VC_CONTAINER_CONTROL_TRACK_ADD: |
| 80 | if(p_ctx->tracks_num >= 2) return VC_CONTAINER_ERROR_OUT_OF_RESOURCES; |
| 81 | |
| 82 | /* Allocate and initialise track data */ |
| 83 | p_ctx->tracks[p_ctx->tracks_num] = track = vc_container_allocate_track(p_ctx, 0); |
| 84 | if(!track) return VC_CONTAINER_ERROR_OUT_OF_MEMORY; |
| 85 | |
| 86 | p_ctx->tracks_num++; |
| 87 | return VC_CONTAINER_SUCCESS; |
| 88 | |
| 89 | case VC_CONTAINER_CONTROL_TRACK_ADD_DONE: |
| 90 | return VC_CONTAINER_SUCCESS; |
| 91 | |
| 92 | default: return VC_CONTAINER_ERROR_UNSUPPORTED_OPERATION; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /*****************************************************************************/ |
| 97 | VC_CONTAINER_STATUS_T dummy_writer_open( VC_CONTAINER_T *p_ctx ) |
| 98 | { |
| 99 | const char *extension = vc_uri_path_extension(p_ctx->priv->uri); |
| 100 | VC_CONTAINER_MODULE_T *module = 0; |
| 101 | VC_CONTAINER_STATUS_T status = VC_CONTAINER_ERROR_FORMAT_INVALID; |
| 102 | |
| 103 | /* Check if the user has specified a container */ |
| 104 | vc_uri_find_query(p_ctx->priv->uri, 0, "container" , &extension); |
| 105 | |
| 106 | /* Check we're the right writer for this */ |
| 107 | if(!extension) |
| 108 | return VC_CONTAINER_ERROR_FORMAT_NOT_SUPPORTED; |
| 109 | if(strcasecmp(extension, "dummy" )) |
| 110 | return VC_CONTAINER_ERROR_FORMAT_NOT_SUPPORTED; |
| 111 | |
| 112 | /* Allocate our context */ |
| 113 | module = malloc(sizeof(*module)); |
| 114 | if(!module) { status = VC_CONTAINER_ERROR_OUT_OF_MEMORY; goto error; } |
| 115 | memset(module, 0, sizeof(*module)); |
| 116 | p_ctx->priv->module = module; |
| 117 | p_ctx->tracks = module->track; |
| 118 | |
| 119 | p_ctx->capabilities |= VC_CONTAINER_CAPS_DYNAMIC_TRACK_ADD; |
| 120 | |
| 121 | p_ctx->priv->pf_close = dummy_writer_close; |
| 122 | p_ctx->priv->pf_write = dummy_writer_write; |
| 123 | p_ctx->priv->pf_control = dummy_writer_control; |
| 124 | return VC_CONTAINER_SUCCESS; |
| 125 | |
| 126 | error: |
| 127 | LOG_DEBUG(p_ctx, "dummy: error opening stream (%i)" , status); |
| 128 | return status; |
| 129 | } |
| 130 | |
| 131 | /******************************************************************************** |
| 132 | Entrypoint function |
| 133 | ********************************************************************************/ |
| 134 | |
| 135 | #if !defined(ENABLE_CONTAINERS_STANDALONE) && defined(__HIGHC__) |
| 136 | # pragma weak writer_open dummy_writer_open |
| 137 | #endif |
| 138 | |