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
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 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 General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, 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 *****************************************************************************/
58 input_attachment_t
*a
;
61 static ssize_t
Read(access_t
*, uint8_t *, size_t);
62 static int Seek(access_t
*, uint64_t);
63 static int Control(access_t
*, int, va_list);
66 static int Open(vlc_object_t
*object
)
68 access_t
*access
= (access_t
*)object
;
71 input_thread_t
*input
= access_GetParentInput(access
);
75 input_attachment_t
*a
;
76 if (input_Control(input
, INPUT_GET_ATTACHMENT
, &a
, access
->psz_location
))
79 vlc_object_release(input
);
82 msg_Err(access
, "Failed to find the attachment '%s'",
83 access
->psz_location
);
88 access
->p_sys
= sys
= malloc(sizeof(*sys
));
90 vlc_input_attachment_Delete(a
);
96 access_InitFields(access
);
97 access
->pf_read
= Read
;
98 access
->pf_block
= NULL
;
99 access
->pf_control
= Control
;
100 access
->pf_seek
= Seek
;
106 static void Close(vlc_object_t
*object
)
108 access_t
*access
= (access_t
*)object
;
109 access_sys_t
*sys
= access
->p_sys
;
111 vlc_input_attachment_Delete(sys
->a
);
116 static ssize_t
Read(access_t
*access
, uint8_t *buffer
, size_t size
)
118 access_sys_t
*sys
= access
->p_sys
;
120 access
->info
.b_eof
= access
->info
.i_pos
>= sys
->a
->i_data
;
121 if (access
->info
.b_eof
)
124 const size_t copy
= __MIN(size
, sys
->a
->i_data
- access
->info
.i_pos
);
125 memcpy(buffer
, (uint8_t*)sys
->a
->p_data
+ access
->info
.i_pos
, copy
);
126 access
->info
.i_pos
+= copy
;
131 static int Seek(access_t
*access
, uint64_t position
)
133 access
->info
.i_pos
= position
;
134 access
->info
.b_eof
= false;
139 static int Control(access_t
*access
, int query
, va_list args
)
145 case ACCESS_CAN_SEEK
:
146 case ACCESS_CAN_FASTSEEK
:
147 case ACCESS_CAN_PAUSE
:
148 case ACCESS_CAN_CONTROL_PACE
: {
149 bool *b
= va_arg(args
, bool*);
153 case ACCESS_GET_PTS_DELAY
: {
154 int64_t *d
= va_arg(args
, int64_t *);
155 *d
= DEFAULT_PTS_DELAY
;
158 case ACCESS_SET_PAUSE_STATE
: