1 /*****************************************************************************
2 * attachment.c: Input reading an attachment.
3 *****************************************************************************
4 * Copyright (C) 2009 Laurent Aimar
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 /*****************************************************************************
26 *****************************************************************************/
32 #include <vlc_common.h>
33 #include <vlc_plugin.h>
34 #include <vlc_access.h>
35 #include <vlc_input.h>
37 /*****************************************************************************
39 *****************************************************************************/
40 static int Open (vlc_object_t
*);
41 static void Close(vlc_object_t
*);
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
)
54 /*****************************************************************************
56 *****************************************************************************/
57 static ssize_t
Read(stream_t
*, void *, size_t);
58 static int Seek(stream_t
*, uint64_t);
59 static int Control(stream_t
*, int, va_list);
63 input_attachment_t
*attachment
;
68 static int Open(vlc_object_t
*object
)
70 stream_t
*access
= (stream_t
*)object
;
72 input_thread_t
*input
= access
->p_input
;
76 access_sys_t
*sys
= vlc_malloc(object
, sizeof (*sys
));
77 if (unlikely(sys
== NULL
))
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
);
93 access
->pf_read
= Read
;
94 access
->pf_block
= NULL
;
95 access
->pf_control
= Control
;
96 access
->pf_seek
= Seek
;
102 static void Close(vlc_object_t
*object
)
104 stream_t
*access
= (stream_t
*)object
;
105 access_sys_t
*sys
= access
->p_sys
;
107 vlc_input_attachment_Delete(sys
->attachment
);
111 static ssize_t
Read(stream_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
)
119 const size_t copy
= __MIN(size
, a
->i_data
- sys
->offset
);
120 memcpy(buffer
, (uint8_t *)a
->p_data
+ sys
->offset
, copy
);
126 static int Seek(stream_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
;
139 static int Control(stream_t
*access
, int query
, va_list args
)
141 access_sys_t
*sys
= access
->p_sys
;
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;
151 case STREAM_GET_SIZE
:
152 *va_arg(args
, uint64_t *) = sys
->attachment
->i_data
;
154 case STREAM_GET_PTS_DELAY
:
155 *va_arg(args
, int64_t *) = DEFAULT_PTS_DELAY
;
157 case STREAM_SET_PAUSE_STATE
: