demux: mkv: handle WAVE_FORMAT_MPEG_ADTS_AAC
[vlc.git] / modules / access / attachment.c
blob98bdc93de6d9111c81bbf995d17f99fc4f8c7ebd
1 /*****************************************************************************
2 * attachment.c: Input reading an attachment.
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
5 * $Id$
7 * Authors: Laurent Aimar <fenrir _AT_ videolan _DOT_ org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
28 #ifdef HAVE_CONFIG_H
29 # include "config.h"
30 #endif
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
35 #include <vlc_input.h>
37 /*****************************************************************************
38 * Module descriptor
39 *****************************************************************************/
40 static int Open (vlc_object_t *);
41 static void Close(vlc_object_t *);
43 vlc_module_begin()
44 set_shortname(N_("Attachment"))
45 set_description(N_("Attachment input"))
46 set_category(CAT_INPUT)
47 set_subcategory(SUBCAT_INPUT_ACCESS)
49 set_capability("access", 0)
50 add_shortcut("attachment")
51 set_callbacks(Open, Close)
52 vlc_module_end()
54 /*****************************************************************************
55 * Local prototypes
56 *****************************************************************************/
57 static ssize_t Read(access_t *, void *, size_t);
58 static int Seek(access_t *, uint64_t);
59 static int Control(access_t *, int, va_list);
61 struct access_sys_t
63 input_attachment_t *attachment;
64 size_t offset;
67 /* */
68 static int Open(vlc_object_t *object)
70 access_t *access = (access_t *)object;
72 input_thread_t *input = access->p_input;
73 if (!input)
74 return VLC_EGENERIC;
76 access_sys_t *sys = vlc_malloc(object, sizeof (*sys));
77 if (unlikely(sys == NULL))
78 return VLC_ENOMEM;
80 if (input_Control(input, INPUT_GET_ATTACHMENT, &sys->attachment,
81 access->psz_location))
82 sys->attachment = NULL;
84 if (sys->attachment == NULL) {
85 msg_Err(access, "Failed to find the attachment '%s'",
86 access->psz_location);
87 return VLC_EGENERIC;
90 sys->offset = 0;
92 /* */
93 access->pf_read = Read;
94 access->pf_block = NULL;
95 access->pf_control = Control;
96 access->pf_seek = Seek;
97 access->p_sys = sys;
98 return VLC_SUCCESS;
101 /* */
102 static void Close(vlc_object_t *object)
104 access_t *access = (access_t *)object;
105 access_sys_t *sys = access->p_sys;
107 vlc_input_attachment_Delete(sys->attachment);
110 /* */
111 static ssize_t Read(access_t *access, void *buffer, size_t size)
113 access_sys_t *sys = access->p_sys;
114 input_attachment_t *a = sys->attachment;
116 if (sys->offset >= (uint64_t)a->i_data)
117 return 0;
119 const size_t copy = __MIN(size, a->i_data - sys->offset);
120 memcpy(buffer, (uint8_t *)a->p_data + sys->offset, copy);
121 sys->offset += copy;
122 return copy;
125 /* */
126 static int Seek(access_t *access, uint64_t position)
128 access_sys_t *sys = access->p_sys;
129 input_attachment_t *a = sys->attachment;
131 if (position > a->i_data)
132 position = a->i_data;
134 sys->offset = position;
135 return VLC_SUCCESS;
138 /* */
139 static int Control(access_t *access, int query, va_list args)
141 access_sys_t *sys = access->p_sys;
143 switch (query)
145 case STREAM_CAN_SEEK:
146 case STREAM_CAN_FASTSEEK:
147 case STREAM_CAN_PAUSE:
148 case STREAM_CAN_CONTROL_PACE:
149 *va_arg(args, bool *) = true;
150 break;
151 case STREAM_GET_SIZE:
152 *va_arg(args, uint64_t *) = sys->attachment->i_data;
153 break;
154 case STREAM_GET_PTS_DELAY:
155 *va_arg(args, int64_t *) = DEFAULT_PTS_DELAY;
156 break;
157 case STREAM_SET_PAUSE_STATE:
158 return VLC_SUCCESS;
160 default:
161 return VLC_EGENERIC;
163 return VLC_SUCCESS;