Difference between revisions of "Hacker Guide/Access"

From VideoLAN Wiki
Jump to navigation Jump to search
Line 21: Line 21:
 
   
 
   
 
As you can see {{VLCSourceFile|name=include/vlc_access.h}}, you should define:
 
As you can see {{VLCSourceFile|name=include/vlc_access.h}}, you should define:
* Seek
+
* Seek, as in pf_seek
* Control
+
* Control, as in pf_control
 
* Read or Block
 
* Read or Block
  
=== ===
+
Your module can be of a 'Block' or a 'Read' type, depending on what you need to access.
  
int        (*pf_seek) ( access_t *, uint64_t );        /* can be null if can't seek */
+
After implementing those function, you should assign them to the corresponding pf_ function.
  91    /* pf_read/pf_block is used to read data.
 
  
  92      * XXX A access should set one and only one of them */
+
== Seek ==
 +
int        (*pf_seek) ( access_t *, uint64_t );
  
  93    ssize_t    (*pf_read) ( access_t *, uint8_t *, size_t );  /* Return -1 if no data yet, 0 if no more data, else real data read */
+
Seeking function can be NULL, if it isn't possible to seek in the protocol or device.
  
  94    block_t    *(*pf_block)( access_t * );                 /* return a block of data in his 'natural' size, NULL if not yet data or eof */
+
== Control ==
 +
int        (*pf_control)( access_t *, int i_query, va_list args);
  
  95
+
== Read ==
 +
ssize_t    (*pf_read) ( access_t *, uint8_t *, size_t );  /* Return -1 if no data yet, 0 if no more data, else real data read */
  
  96    /* Called for each seek.
+
== Block ==
 
+
block_t    *(*pf_block)( access_t * );                 /* return a block of data in his 'natural' size, NULL if not yet data or eof */
  97      * XXX can be null */
 
 
 
  98    int        (*pf_seek) ( access_t *, uint64_t );         /* can be null if can't seek */
 
 
 
  99
 
 
 
100    /* Used to retreive and configure the access
 
 
 
101      * XXX mandatory. look at access_query_e to know what query you *have to* support */
 
 
 
102    int        (*pf_control)( access_t *, int i_query, va_list args);
 
  
 
== Functionality  ==
 
== Functionality  ==

Revision as of 16:14, 11 November 2010

Description

The modules of 'access' capability are designed to be the first and last elements of a modules chain.

Access input and output handles most of the basic I/O for VLC. They are usually protocols implementations (http, ftp,...) or devices access (Webcams, Capture cards).

We will discuss about 'input access' in this page.

Starting to write an access module

To write an access module, read the introduction to module writing.

Then, you should specify your module of being of access type:

set_capability( "access", 60 )  
set_category( CAT_INPUT )                                                                                                                                                                                  
set_subcategory( SUBCAT_INPUT_ACCESS )

Functions to implement

After implementing Open() and Close() functions, you will need to implement a few majors features that will be implemented by your functions.

As you can see include/vlc_access.h, you should define:

  • Seek, as in pf_seek
  • Control, as in pf_control
  • Read or Block

Your module can be of a 'Block' or a 'Read' type, depending on what you need to access.

After implementing those function, you should assign them to the corresponding pf_ function.

Seek

int         (*pf_seek) ( access_t *, uint64_t );

Seeking function can be NULL, if it isn't possible to seek in the protocol or device.

Control

int         (*pf_control)( access_t *, int i_query, va_list args);

Read

ssize_t     (*pf_read) ( access_t *, uint8_t *, size_t );  /* Return -1 if no data yet, 0 if no more data, else real data read */

Block

block_t    *(*pf_block)( access_t * );                  /* return a block of data in his 'natural' size, NULL if not yet data or eof */

Functionality

Generally speaking, access input will provide Read() functions and output Write().

Both needs to provide Seek() and Control() even if the underlying architecture does not support these actions. In this case, Seek() and Control() should return VLC_EGENERIC, although Control() might need to answer ACCESS_OUT_CONTROLS_PACE requests. See modules/access_output/http.c about using a source without seeking.