2003-08-01 02:00:12 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* stream.c
|
|
|
|
*****************************************************************************
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* Copyright (C) 1999-2004 VLC authors and VideoLAN
|
2015-07-23 18:24:34 +02:00
|
|
|
* Copyright 2008-2015 Rémi Denis-Courmont
|
2003-08-01 02:00:12 +02:00
|
|
|
*
|
|
|
|
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
|
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2003-08-01 02:00:12 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
2003-08-01 02:00:12 +02:00
|
|
|
*
|
LGPL
Re-license almost all of libVLC and libVLCcore to LGPLv2.1+
This move was authorized by the developers, either:
- by e-mail,
- by vote at the VideoLAN Dev Days 2011,
- on the license website,
- in a contract, oral or written.
No objection was raised, so far.
The developers agreeing are:
Justus Piater
Alexis Ballier
Alexander Bethke
Mohammed Adnène Trojette
Alex Converse
Alexey Sokolov
Alexis de Lattre
Andre Pang
Anthony Loiseau
Cyril Deguet
André Weber
Boris Dorès
Brieuc Jeunhomme
Benjamin Drung
Hugo Beauzée-Luyssen
Benoit Steiner
Benjamin Pracht
Bernie Purcell
Przemyslaw Fiala
Arnaud de Bossoreille de Ribou
Brad Smith
Nick Briggs
Christopher Rath
Christophe Courtaut
Christopher Mueller
Clement Chesnin
Andres Krapf
Damien Fouilleul
David Flynn
Sebastien Zwickert
Antoine Cellerier
Jérôme Decoodt
Jérome Decoodt
Dylan Yudaken
Eduard Babayan
Eugenio Jarosiewicz
Elliot Murphy
Eric Petit
Erwan Tulou
Etienne Membrives
Ludovic Fauvet
Fabio Ritrovato
Tobias Güntner
Jakub Wieczorek
Frédéric Crozat
Francois Cartegnie
Laurent Aimar
Florian G. Pflug
Felix Paul Kühne
Frank Enderle
Rafaël Carré
Simon Latapie
Gildas Bazin
Geoffroy Couprie
Julien / Gellule
Gildas Bazin
Arnaud Schauly
Toralf Niebuhr
Vicente Jimenez Aguilar
Derk-Jan Hartman
Henri Fallon
Ilkka Ollakka
Olivier Teulière
Rémi Duraffort
Jakob Leben
Jean-Baptiste Kempf
Jean-Paul Saman
Jean-Philippe Grimaldi
Jean-François Massol
Gaël Hendryckx
Jakob Leben
Jean-Marc Dressler
Jai Menon
Johan Bilien
Johann Ransay
Joris van Rooij
JP Dinger
Jean-Philippe André
Adrien Grand
Juha Jeronen
Juho Vähä-Herttua
Kaarlo Raiha
Kaarlo Raiha
Kamil Baldyga
Keary Griffin
Ken Self
KO Myung-Hun
Pierre Ynard
Filippo Carone
Loïc Minier
Luca Barbato
Lucas C. Villa Real
Lukas Durfina
Adrien Maglo
Marc Ariberti
Mark Lee
Mark Moriarty
Martin Storsjö
Christophe Massiot
Michel Kaempf
Marian Ďurkovič
Mirsal Ennaime
Carlo Calabrò
Damien Lucas
Naohiro Koriyama
Basos G
Pierre Baillet
Vincent Penquerc'h
Olivier Aubert
Pankaj Yadav
Paul Corke
Pierre d'Herbemont
Philippe Morin
Antoine Lejeune
Michael Ploujnikov
Jean-Marc Dressler
Michael Hanselmann
Rafaël Carré
Ramiro Polla
Rémi Denis-Courmont
Renaud Dartus
Richard Shepherd
Faustino Osuna
Arnaud Vallat
Rob Jonson
Robert Jedrzejczyk
Steve Lhomme
Rocky Bernstein
Romain Goyet
Rov Juvano
Sam Hocevar
Martin T. H. Sandsmark
Sebastian Birk
Sébastien Escudier
Vincent Seguin
Fabio Ritrovato
Sigmund Augdal Helberg
Casian Andrei
Srikanth Raju
Hannes Domani
Stéphane Borel
Stephan Krempel
Stephan Assmus
Tony Castley
Pavlov Konstantin
Eric Petit
Tanguy Krotoff
Dennis van Amerongen
Michel Lespinasse
Can Wu
Xavier Marchesini
Sébastien Toque
Christophe Mutricy
Yoann Peronneau
Yohann Martineau
Yuval Tze
Scott Caudle
Clément Stenac
It is possible, that some minor piece of code was badly tracked, for
some reasons (SVN, mainly) or that some small developers did not answer.
However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3",
and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and
the very vast majority of developers have agreed (> 99.99% of the code,
> 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
|
2003-08-01 02:00:12 +02:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-01-23 22:50:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-10-13 20:20:54 +02:00
|
|
|
#include <assert.h>
|
2023-01-30 16:49:28 +01:00
|
|
|
#include <stdbool.h>
|
2018-04-06 19:05:21 +02:00
|
|
|
#include <stdalign.h>
|
2015-07-23 18:04:56 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2015-08-31 18:59:22 +02:00
|
|
|
#include <limits.h>
|
2017-05-24 18:43:39 +02:00
|
|
|
#include <errno.h>
|
2008-08-26 12:54:18 +02:00
|
|
|
|
2008-05-31 20:56:22 +02:00
|
|
|
#include <vlc_common.h>
|
2015-07-23 19:36:38 +02:00
|
|
|
#include <vlc_block.h>
|
2015-07-23 18:04:56 +02:00
|
|
|
#include <vlc_access.h>
|
2015-07-23 18:24:34 +02:00
|
|
|
#include <vlc_charset.h>
|
2015-08-24 21:18:28 +02:00
|
|
|
#include <vlc_interrupt.h>
|
2017-03-17 11:55:40 +01:00
|
|
|
#include <vlc_stream_extractor.h>
|
2003-08-01 02:00:12 +02:00
|
|
|
|
2008-10-13 20:20:54 +02:00
|
|
|
#include <libvlc.h>
|
|
|
|
#include "stream.h"
|
2017-03-17 11:55:40 +01:00
|
|
|
#include "mrl_helpers.h"
|
2008-10-13 20:20:54 +02:00
|
|
|
|
2015-07-23 18:24:34 +02:00
|
|
|
typedef struct stream_priv_t
|
2008-10-13 20:31:32 +02:00
|
|
|
{
|
2015-07-23 18:24:34 +02:00
|
|
|
stream_t stream;
|
2015-09-02 19:49:40 +02:00
|
|
|
void (*destroy)(stream_t *);
|
2016-07-19 22:34:37 +02:00
|
|
|
block_t *block;
|
2015-07-23 19:36:38 +02:00
|
|
|
block_t *peek;
|
2015-08-31 21:19:32 +02:00
|
|
|
uint64_t offset;
|
2016-07-19 19:28:49 +02:00
|
|
|
bool eof;
|
2008-12-08 21:50:21 +01:00
|
|
|
|
2015-07-23 18:24:34 +02:00
|
|
|
/* UTF-16 and UTF-32 file reading */
|
|
|
|
struct {
|
|
|
|
vlc_iconv_t conv;
|
|
|
|
unsigned char char_width;
|
|
|
|
bool little_endian;
|
|
|
|
} text;
|
2018-04-06 19:05:21 +02:00
|
|
|
|
|
|
|
max_align_t private_data[];
|
2015-07-23 18:24:34 +02:00
|
|
|
} stream_priv_t;
|
2008-12-08 21:50:21 +01:00
|
|
|
|
2015-07-23 18:24:34 +02:00
|
|
|
/**
|
|
|
|
* Allocates a VLC stream object
|
|
|
|
*/
|
2018-04-06 19:05:21 +02:00
|
|
|
stream_t *vlc_stream_CustomNew(vlc_object_t *parent,
|
|
|
|
void (*destroy)(stream_t *), size_t size,
|
|
|
|
const char *type_name)
|
2015-07-23 18:24:34 +02:00
|
|
|
{
|
2018-04-06 19:05:21 +02:00
|
|
|
stream_priv_t *priv = vlc_custom_create(parent, sizeof (*priv) + size,
|
|
|
|
type_name);
|
2015-07-23 18:24:34 +02:00
|
|
|
if (unlikely(priv == NULL))
|
2008-12-08 21:50:21 +01:00
|
|
|
return NULL;
|
2015-07-23 18:24:34 +02:00
|
|
|
|
2022-01-10 14:35:33 +01:00
|
|
|
stream_t *s = &priv->stream;
|
|
|
|
|
2022-01-10 14:44:50 +01:00
|
|
|
s->psz_name = NULL;
|
2022-01-10 14:35:33 +01:00
|
|
|
s->psz_url = NULL;
|
2022-01-10 14:44:50 +01:00
|
|
|
s->psz_location = NULL;
|
2022-01-10 14:35:33 +01:00
|
|
|
s->psz_filepath = NULL;
|
2022-01-10 14:44:50 +01:00
|
|
|
s->b_preparsing = false;
|
|
|
|
s->p_input_item = NULL;
|
2022-01-10 14:35:33 +01:00
|
|
|
s->s = NULL;
|
2022-01-10 14:44:50 +01:00
|
|
|
s->out = NULL;
|
2022-01-10 14:35:33 +01:00
|
|
|
s->pf_read = NULL;
|
|
|
|
s->pf_block = NULL;
|
|
|
|
s->pf_readdir = NULL;
|
2022-01-10 14:44:50 +01:00
|
|
|
s->pf_demux = NULL;
|
2022-01-10 14:35:33 +01:00
|
|
|
s->pf_seek = NULL;
|
|
|
|
s->pf_control = NULL;
|
|
|
|
s->p_sys = NULL;
|
2023-01-30 16:49:28 +01:00
|
|
|
s->ops = NULL;
|
2015-09-02 19:49:40 +02:00
|
|
|
assert(destroy != NULL);
|
|
|
|
priv->destroy = destroy;
|
2022-01-10 14:35:33 +01:00
|
|
|
priv->block = NULL;
|
|
|
|
priv->peek = NULL;
|
|
|
|
priv->offset = 0;
|
|
|
|
priv->eof = false;
|
2008-12-08 21:50:21 +01:00
|
|
|
|
|
|
|
/* UTF16 and UTF32 text file conversion */
|
2015-07-23 18:24:34 +02:00
|
|
|
priv->text.conv = (vlc_iconv_t)(-1);
|
|
|
|
priv->text.char_width = 1;
|
2022-01-10 14:35:33 +01:00
|
|
|
priv->text.little_endian = false;
|
2008-12-08 21:50:21 +01:00
|
|
|
|
2022-01-06 23:25:45 +01:00
|
|
|
return &priv->stream;
|
2008-12-08 21:50:21 +01:00
|
|
|
}
|
2009-08-21 12:27:56 +02:00
|
|
|
|
2022-04-26 15:24:19 +02:00
|
|
|
#define stream_priv(s) container_of(s, stream_priv_t, stream)
|
|
|
|
|
2018-04-06 19:05:21 +02:00
|
|
|
void *vlc_stream_Private(stream_t *stream)
|
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
return stream_priv(stream)->private_data;
|
2018-04-06 19:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stream_t *vlc_stream_CommonNew(vlc_object_t *parent,
|
|
|
|
void (*destroy)(stream_t *))
|
|
|
|
{
|
|
|
|
return vlc_stream_CustomNew(parent, destroy, 0, "stream");
|
|
|
|
}
|
|
|
|
|
2015-09-02 19:49:40 +02:00
|
|
|
void stream_CommonDelete(stream_t *s)
|
2008-12-08 21:50:21 +01:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2015-07-23 18:24:34 +02:00
|
|
|
|
|
|
|
if (priv->text.conv != (vlc_iconv_t)(-1))
|
|
|
|
vlc_iconv_close(priv->text.conv);
|
2015-08-29 18:43:18 +02:00
|
|
|
|
2015-07-23 19:36:38 +02:00
|
|
|
if (priv->peek != NULL)
|
|
|
|
block_Release(priv->peek);
|
2016-07-19 22:34:37 +02:00
|
|
|
if (priv->block != NULL)
|
|
|
|
block_Release(priv->block);
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2015-07-26 12:47:54 +02:00
|
|
|
free(s->psz_url);
|
2019-03-06 19:15:18 +01:00
|
|
|
vlc_object_delete(s);
|
2008-10-13 20:31:32 +02:00
|
|
|
}
|
|
|
|
|
2015-09-02 19:49:40 +02:00
|
|
|
/**
|
|
|
|
* Destroy a stream
|
|
|
|
*/
|
2016-07-20 22:02:54 +02:00
|
|
|
void vlc_stream_Delete(stream_t *s)
|
2015-09-02 19:49:40 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2015-09-02 19:49:40 +02:00
|
|
|
|
2023-01-30 16:49:28 +01:00
|
|
|
if (s->ops != NULL && s->ops->close != NULL) {
|
|
|
|
s->ops->close(s);
|
|
|
|
}
|
2015-09-02 19:49:40 +02:00
|
|
|
priv->destroy(s);
|
|
|
|
stream_CommonDelete(s);
|
|
|
|
}
|
|
|
|
|
2016-10-28 12:22:07 +02:00
|
|
|
stream_t *(vlc_stream_NewURL)(vlc_object_t *p_parent, const char *psz_url)
|
2005-04-01 20:37:31 +02:00
|
|
|
{
|
2008-08-22 02:23:43 +02:00
|
|
|
if( !psz_url )
|
|
|
|
return NULL;
|
2005-04-12 20:15:33 +02:00
|
|
|
|
2018-03-24 11:38:59 +01:00
|
|
|
stream_t *s = stream_AccessNew( p_parent, NULL, NULL, false, psz_url );
|
2015-07-26 15:36:35 +02:00
|
|
|
if( s == NULL )
|
2005-04-01 20:37:31 +02:00
|
|
|
msg_Err( p_parent, "no suitable access module for `%s'", psz_url );
|
2018-04-16 16:22:25 +02:00
|
|
|
else
|
|
|
|
s = stream_FilterAutoNew(s);
|
2015-07-26 15:36:35 +02:00
|
|
|
return s;
|
2005-04-01 20:37:31 +02:00
|
|
|
}
|
|
|
|
|
2017-03-17 11:55:40 +01:00
|
|
|
stream_t *(vlc_stream_NewMRL)(vlc_object_t* parent, const char* mrl )
|
|
|
|
{
|
|
|
|
stream_t* stream = vlc_stream_NewURL( parent, mrl );
|
|
|
|
|
|
|
|
if( stream == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
char const* anchor = strchr( mrl, '#' );
|
|
|
|
|
|
|
|
if( anchor == NULL )
|
|
|
|
return stream;
|
|
|
|
|
|
|
|
char const* extra;
|
|
|
|
if( stream_extractor_AttachParsed( &stream, anchor + 1, &extra ) )
|
|
|
|
{
|
|
|
|
msg_Err( parent, "unable to open %s", mrl );
|
|
|
|
vlc_stream_Delete( stream );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( extra && *extra )
|
|
|
|
msg_Warn( parent, "ignoring extra fragment data: %s", extra );
|
|
|
|
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2004-06-22 21:29:57 +02:00
|
|
|
/**
|
2016-04-02 16:50:37 +02:00
|
|
|
* Read from the stream until first newline.
|
2004-06-22 21:29:57 +02:00
|
|
|
* \param s Stream handle to read from
|
2005-12-11 00:47:34 +01:00
|
|
|
* \return A pointer to the allocated output string. You need to free this when you are done.
|
2004-06-22 21:29:57 +02:00
|
|
|
*/
|
2004-07-09 17:15:07 +02:00
|
|
|
#define STREAM_PROBE_LINE 2048
|
|
|
|
#define STREAM_LINE_MAX (2048*100)
|
2016-07-20 22:02:54 +02:00
|
|
|
char *vlc_stream_ReadLine( stream_t *s )
|
2004-06-22 21:29:57 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2004-03-29 16:25:25 +02:00
|
|
|
|
2014-06-21 15:55:10 +02:00
|
|
|
/* Let's fail quickly if this is a readdir access */
|
2023-03-17 11:48:19 +01:00
|
|
|
if( (s->ops != NULL && s->ops->stream.read == NULL && s->ops->stream.block == NULL) ||
|
|
|
|
(s->ops == NULL && s->pf_read == NULL && s->pf_block == NULL) )
|
2014-06-21 15:55:10 +02:00
|
|
|
return NULL;
|
|
|
|
|
2020-10-27 08:56:06 +01:00
|
|
|
/* BOM detection */
|
|
|
|
if( vlc_stream_Tell( s ) == 0 )
|
2004-06-22 21:29:57 +02:00
|
|
|
{
|
2007-07-20 16:22:54 +02:00
|
|
|
const uint8_t *p_data;
|
2020-10-27 08:56:06 +01:00
|
|
|
ssize_t i_data = vlc_stream_Peek( s, &p_data, 2 );
|
2004-06-25 20:35:56 +02:00
|
|
|
|
2020-10-27 08:56:06 +01:00
|
|
|
if( i_data <= 0 )
|
|
|
|
return NULL;
|
2004-06-25 20:35:56 +02:00
|
|
|
|
2020-10-27 08:56:06 +01:00
|
|
|
if( unlikely(priv->text.conv != (vlc_iconv_t)-1) )
|
|
|
|
{ /* seek back to beginning? reset */
|
|
|
|
vlc_iconv_close( priv->text.conv );
|
|
|
|
priv->text.conv = (vlc_iconv_t)-1;
|
|
|
|
}
|
|
|
|
priv->text.char_width = 1;
|
|
|
|
priv->text.little_endian = false;
|
|
|
|
|
|
|
|
if( i_data >= 2 )
|
2005-12-11 00:47:34 +01:00
|
|
|
{
|
2008-08-31 20:31:57 +02:00
|
|
|
const char *psz_encoding = NULL;
|
2020-10-03 12:02:38 +02:00
|
|
|
bool little_endian = false;
|
2006-10-23 23:02:45 +02:00
|
|
|
|
2012-06-27 17:58:24 +02:00
|
|
|
if( !memcmp( p_data, "\xFF\xFE", 2 ) )
|
2005-12-11 00:47:34 +01:00
|
|
|
{
|
2008-08-31 20:31:57 +02:00
|
|
|
psz_encoding = "UTF-16LE";
|
2020-10-03 12:02:38 +02:00
|
|
|
little_endian = true;
|
2005-12-11 00:47:34 +01:00
|
|
|
}
|
2008-08-31 20:31:57 +02:00
|
|
|
else if( !memcmp( p_data, "\xFE\xFF", 2 ) )
|
2005-12-11 00:47:34 +01:00
|
|
|
{
|
2008-08-31 20:31:57 +02:00
|
|
|
psz_encoding = "UTF-16BE";
|
2005-12-11 00:59:43 +01:00
|
|
|
}
|
2005-12-11 00:47:34 +01:00
|
|
|
|
|
|
|
/* Open the converter if we need it */
|
|
|
|
if( psz_encoding != NULL )
|
|
|
|
{
|
2012-06-27 17:58:24 +02:00
|
|
|
msg_Dbg( s, "UTF-16 BOM detected" );
|
2015-07-23 18:24:34 +02:00
|
|
|
priv->text.conv = vlc_iconv_open( "UTF-8", psz_encoding );
|
2017-06-21 20:08:56 +02:00
|
|
|
if( unlikely(priv->text.conv == (vlc_iconv_t)-1) )
|
|
|
|
{
|
2012-06-27 17:58:24 +02:00
|
|
|
msg_Err( s, "iconv_open failed" );
|
2020-10-27 08:56:06 +01:00
|
|
|
return NULL;
|
2017-06-21 20:08:56 +02:00
|
|
|
}
|
|
|
|
priv->text.char_width = 2;
|
2020-10-03 12:02:38 +02:00
|
|
|
priv->text.little_endian = little_endian;
|
2005-12-11 00:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-10-27 08:56:06 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
size_t i_line = 0;
|
|
|
|
const uint8_t *p_data;
|
|
|
|
|
2020-10-27 08:56:06 +01:00
|
|
|
for( ;; )
|
|
|
|
{
|
2020-10-27 09:01:25 +01:00
|
|
|
size_t i_peek = i_line == 0 ? STREAM_PROBE_LINE
|
|
|
|
: __MIN( i_line * 2, STREAM_LINE_MAX );
|
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
/* Probe more data */
|
2020-10-27 09:01:25 +01:00
|
|
|
ssize_t i_data = vlc_stream_Peek( s, &p_data, i_peek );
|
2020-10-27 08:59:57 +01:00
|
|
|
if( i_data <= 0 )
|
|
|
|
return NULL;
|
2005-12-11 00:47:34 +01:00
|
|
|
|
2020-10-27 08:54:24 +01:00
|
|
|
/* Deal here with lone-byte incomplete UTF-16 sequences at EOF
|
|
|
|
that we won't be able to process anyway */
|
|
|
|
if( i_data < priv->text.char_width )
|
2005-12-11 00:47:34 +01:00
|
|
|
{
|
2020-10-27 08:54:24 +01:00
|
|
|
assert( priv->text.char_width == 2 );
|
|
|
|
uint8_t inc;
|
|
|
|
ssize_t i_inc = vlc_stream_Read( s, &inc, priv->text.char_width );
|
|
|
|
assert( i_inc == i_data );
|
|
|
|
if( i_inc > 0 )
|
|
|
|
msg_Err( s, "discarding incomplete UTF-16 sequence at EOF: 0x%02x", inc );
|
2020-10-27 08:59:57 +01:00
|
|
|
return NULL;
|
2005-12-11 00:47:34 +01:00
|
|
|
}
|
|
|
|
|
2020-10-27 08:54:24 +01:00
|
|
|
/* Keep to text encoding character width boundary */
|
|
|
|
if( i_data % priv->text.char_width )
|
|
|
|
i_data = i_data - ( i_data % priv->text.char_width );
|
2006-11-27 02:44:14 +01:00
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
if( (size_t) i_data == i_line )
|
|
|
|
break; /* No more data */
|
|
|
|
|
|
|
|
assert( (size_t) i_data > i_line );
|
|
|
|
|
|
|
|
/* Resume search for an EOL where we left off */
|
|
|
|
const uint8_t *p_cur = p_data + i_line, *psz_eol;
|
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
/* FIXME: <CR> behavior varies depending on where buffer
|
|
|
|
boundaries happen to fall; a <CR><LF> across the boundary
|
|
|
|
creates a bogus empty line. */
|
2015-07-23 18:24:34 +02:00
|
|
|
if( priv->text.char_width == 1 )
|
2004-06-22 21:29:57 +02:00
|
|
|
{
|
2006-11-27 02:44:14 +01:00
|
|
|
/* UTF-8: 0A <LF> */
|
2020-10-27 08:59:57 +01:00
|
|
|
psz_eol = memchr( p_cur, '\n', i_data - i_line );
|
2010-02-17 21:37:36 +01:00
|
|
|
if( psz_eol == NULL )
|
|
|
|
/* UTF-8: 0D <CR> */
|
2020-10-27 08:59:57 +01:00
|
|
|
psz_eol = memchr( p_cur, '\r', i_data - i_line );
|
2006-11-27 02:44:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-07-23 18:24:34 +02:00
|
|
|
const uint8_t *p_last = p_data + i_data - priv->text.char_width;
|
2020-09-17 06:09:06 +02:00
|
|
|
uint16_t eol = priv->text.little_endian ? 0x0A00 : 0x000A;
|
2006-11-27 02:44:14 +01:00
|
|
|
|
2015-07-23 18:24:34 +02:00
|
|
|
assert( priv->text.char_width == 2 );
|
2010-02-17 21:37:36 +01:00
|
|
|
psz_eol = NULL;
|
|
|
|
/* UTF-16: 000A <LF> */
|
2020-10-27 08:59:57 +01:00
|
|
|
for( const uint8_t *p = p_cur; p <= p_last; p += 2 )
|
2005-12-11 00:47:34 +01:00
|
|
|
{
|
2010-02-17 21:37:36 +01:00
|
|
|
if( U16_AT( p ) == eol )
|
|
|
|
{
|
2020-10-27 08:58:02 +01:00
|
|
|
psz_eol = p;
|
2010-02-17 21:37:36 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-12-11 00:47:34 +01:00
|
|
|
}
|
2006-11-27 02:44:14 +01:00
|
|
|
|
2010-02-17 21:37:36 +01:00
|
|
|
if( psz_eol == NULL )
|
|
|
|
{ /* UTF-16: 000D <CR> */
|
2020-09-17 06:09:06 +02:00
|
|
|
eol = priv->text.little_endian ? 0x0D00 : 0x000D;
|
2020-10-27 08:59:57 +01:00
|
|
|
for( const uint8_t *p = p_cur; p <= p_last; p += 2 )
|
2010-02-17 21:37:36 +01:00
|
|
|
{
|
|
|
|
if( U16_AT( p ) == eol )
|
|
|
|
{
|
2020-10-27 08:58:02 +01:00
|
|
|
psz_eol = p;
|
2010-02-17 21:37:36 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-27 02:44:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
if( psz_eol )
|
|
|
|
{
|
2020-10-27 08:59:57 +01:00
|
|
|
i_line = (psz_eol - p_data) + priv->text.char_width;
|
2020-10-27 08:58:02 +01:00
|
|
|
/* We have our line */
|
|
|
|
break;
|
|
|
|
}
|
2013-04-25 17:04:07 +02:00
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
i_line = i_data;
|
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
if( i_line >= STREAM_LINE_MAX )
|
2020-10-27 08:57:08 +01:00
|
|
|
{
|
|
|
|
msg_Err( s, "line too long, exceeding %zu bytes",
|
|
|
|
(size_t) STREAM_LINE_MAX );
|
2020-10-27 08:58:02 +01:00
|
|
|
return NULL;
|
2020-10-27 08:57:08 +01:00
|
|
|
}
|
2004-06-22 21:29:57 +02:00
|
|
|
}
|
2004-06-25 20:35:56 +02:00
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
if( i_line == 0 ) /* We failed to read any data, probably EOF */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* If encoding conversion is required, UTF-8 needs at most 150%
|
|
|
|
as long a buffer as UTF-16 */
|
|
|
|
size_t i_line_conv = priv->text.char_width == 1 ? i_line : i_line * 3 / 2;
|
|
|
|
char *p_line = malloc( i_line_conv + 1 ); /* +1 for easy \0 append */
|
|
|
|
if( !p_line )
|
2020-10-27 08:58:02 +01:00
|
|
|
return NULL;
|
2020-10-27 08:59:57 +01:00
|
|
|
void *p_read = p_line;
|
2020-10-27 08:58:02 +01:00
|
|
|
|
|
|
|
if( priv->text.char_width > 1 )
|
2004-07-09 17:15:07 +02:00
|
|
|
{
|
2020-10-27 08:59:57 +01:00
|
|
|
size_t i_in = i_line, i_out = i_line_conv;
|
|
|
|
const char * p_in = (char *) p_data;
|
|
|
|
char * p_out = p_line;
|
2005-12-11 00:47:34 +01:00
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
if( vlc_iconv( priv->text.conv, &p_in, &i_in, &p_out, &i_out ) == VLC_ICONV_ERR )
|
|
|
|
{
|
|
|
|
msg_Err( s, "conversion error: %s", vlc_strerror_c( errno ) );
|
|
|
|
msg_Dbg( s, "original: %zu, in %zu, out %zu", i_line, i_in, i_out );
|
|
|
|
/* Reset state */
|
|
|
|
size_t r = vlc_iconv( priv->text.conv, NULL, NULL, NULL, NULL );
|
|
|
|
VLC_UNUSED( r );
|
2020-10-27 08:59:57 +01:00
|
|
|
/* FIXME: the rest of the line is discarded and lost */
|
2020-10-27 08:58:02 +01:00
|
|
|
}
|
2020-10-27 08:59:57 +01:00
|
|
|
|
|
|
|
i_line_conv -= i_out;
|
|
|
|
p_read = NULL; /* Line already read, only need to advance the stream */
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t i_data = vlc_stream_Read( s, p_read, i_line );
|
|
|
|
assert( i_data > 0 && (size_t) i_data == i_line );
|
|
|
|
if( i_data <= 0 )
|
|
|
|
{
|
|
|
|
/* Hmmm */
|
2020-10-27 08:58:02 +01:00
|
|
|
free( p_line );
|
2020-10-27 08:59:57 +01:00
|
|
|
return NULL;
|
2020-10-27 08:58:02 +01:00
|
|
|
}
|
2005-12-11 00:47:34 +01:00
|
|
|
|
2020-10-27 08:59:57 +01:00
|
|
|
i_line = i_line_conv;
|
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
/* Remove trailing LF/CR */
|
|
|
|
while( i_line >= 1 &&
|
|
|
|
(p_line[i_line - 1] == '\r' || p_line[i_line - 1] == '\n') )
|
|
|
|
i_line--;
|
2005-12-11 00:47:34 +01:00
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
/* Make sure the \0 is there */
|
|
|
|
p_line[i_line] = '\0';
|
2004-06-25 20:35:56 +02:00
|
|
|
|
2020-10-27 08:58:02 +01:00
|
|
|
return p_line;
|
2004-06-22 21:29:57 +02:00
|
|
|
}
|
2005-01-26 17:12:37 +01:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
static ssize_t vlc_stream_CopyBlock(block_t **restrict pp,
|
|
|
|
void *buf, size_t len)
|
2015-08-24 21:18:28 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
block_t *block = *pp;
|
2015-08-24 21:18:28 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (block == NULL)
|
|
|
|
return -1;
|
2016-07-19 22:34:37 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (len > block->i_buffer)
|
|
|
|
len = block->i_buffer;
|
2016-07-19 22:34:37 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (buf != NULL)
|
|
|
|
memcpy(buf, block->p_buffer, len);
|
2016-07-19 22:34:37 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
block->p_buffer += len;
|
|
|
|
block->i_buffer -= len;
|
2015-08-24 21:18:28 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (block->i_buffer == 0)
|
|
|
|
{
|
|
|
|
block_Release(block);
|
|
|
|
*pp = NULL;
|
2015-08-24 21:18:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
return likely(len > 0) ? (ssize_t)len : -1;
|
2015-08-24 21:18:28 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
static ssize_t vlc_stream_ReadRaw(stream_t *s, void *buf, size_t len)
|
2007-04-18 20:55:19 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2016-07-24 21:47:01 +02:00
|
|
|
ssize_t ret;
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2016-10-31 09:00:39 +01:00
|
|
|
assert(len <= SSIZE_MAX);
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (vlc_killed())
|
2016-07-19 19:28:49 +02:00
|
|
|
return 0;
|
|
|
|
|
2023-03-17 11:48:19 +01:00
|
|
|
if ((s->ops != NULL && s->ops->stream.read != NULL) || (s->ops == NULL && s->pf_read != NULL))
|
2015-07-23 19:36:38 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
assert(priv->block == NULL);
|
2017-02-07 18:56:46 +01:00
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
if (unlikely(len == 0))
|
|
|
|
return 0;
|
|
|
|
|
2020-11-27 15:19:21 +01:00
|
|
|
char dummy[256];
|
2023-03-17 11:48:19 +01:00
|
|
|
ret = (s->ops != NULL ? s->ops->stream.read : s->pf_read)(s, dummy, len <= 256 ? len : 256);
|
2017-02-07 18:56:46 +01:00
|
|
|
}
|
|
|
|
else
|
2023-03-17 11:48:19 +01:00
|
|
|
ret = (s->ops != NULL ? s->ops->stream.read : s->pf_read)(s, buf, len);
|
2016-07-24 21:47:01 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
ret = vlc_stream_CopyBlock(&priv->block, buf, len);
|
|
|
|
if (ret >= 0)
|
|
|
|
return ret;
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2023-03-17 11:48:19 +01:00
|
|
|
if ((s->ops != NULL && s->ops->stream.block != NULL) || (s->ops == NULL && s->pf_block != NULL))
|
2016-07-24 21:47:01 +02:00
|
|
|
{
|
|
|
|
bool eof = false;
|
2016-07-19 19:02:22 +02:00
|
|
|
|
2023-03-17 11:48:19 +01:00
|
|
|
priv->block = (s->ops != NULL ? s->ops->stream.block : s->pf_block)(s, &eof);
|
2016-07-24 21:47:01 +02:00
|
|
|
ret = vlc_stream_CopyBlock(&priv->block, buf, len);
|
|
|
|
if (ret >= 0)
|
|
|
|
return ret;
|
|
|
|
return eof ? 0 : -1;
|
2015-07-23 19:36:38 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
return 0;
|
2007-04-18 20:55:19 +02:00
|
|
|
}
|
|
|
|
|
2016-07-21 20:51:38 +02:00
|
|
|
ssize_t vlc_stream_ReadPartial(stream_t *s, void *buf, size_t len)
|
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2016-07-24 21:47:01 +02:00
|
|
|
ssize_t ret;
|
2016-07-21 20:51:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
ret = vlc_stream_CopyBlock(&priv->peek, buf, len);
|
|
|
|
if (ret >= 0)
|
2016-07-21 20:51:38 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
priv->offset += ret;
|
2017-02-07 18:56:46 +01:00
|
|
|
assert(ret <= (ssize_t)len);
|
2016-07-24 21:47:01 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-07-21 20:51:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
ret = vlc_stream_ReadRaw(s, buf, len);
|
|
|
|
if (ret > 0)
|
|
|
|
priv->offset += ret;
|
|
|
|
if (ret == 0)
|
|
|
|
priv->eof = len != 0;
|
2017-02-07 18:56:46 +01:00
|
|
|
assert(ret <= (ssize_t)len);
|
2016-07-24 21:47:01 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2016-07-21 20:51:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
ssize_t vlc_stream_Read(stream_t *s, void *buf, size_t len)
|
|
|
|
{
|
|
|
|
size_t copied = 0;
|
2016-07-21 20:51:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
while (len > 0)
|
|
|
|
{
|
|
|
|
ssize_t ret = vlc_stream_ReadPartial(s, buf, len);
|
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
if (ret == 0)
|
|
|
|
break;
|
2016-07-21 20:51:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (buf != NULL)
|
|
|
|
buf = (char *)buf + ret;
|
2017-02-07 18:56:46 +01:00
|
|
|
assert(len >= (size_t)ret);
|
2016-07-24 21:47:01 +02:00
|
|
|
len -= ret;
|
|
|
|
copied += ret;
|
2016-07-21 20:51:38 +02:00
|
|
|
}
|
2016-07-24 21:47:01 +02:00
|
|
|
|
|
|
|
return copied;
|
2016-07-21 20:51:38 +02:00
|
|
|
}
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
ssize_t vlc_stream_Peek(stream_t *s, const uint8_t **restrict bufp, size_t len)
|
2007-04-18 20:55:19 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2016-07-24 21:47:01 +02:00
|
|
|
block_t *peek;
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
peek = priv->peek;
|
|
|
|
if (peek == NULL)
|
2016-07-19 22:34:37 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
peek = priv->block;
|
|
|
|
priv->peek = peek;
|
2016-07-19 22:34:37 +02:00
|
|
|
priv->block = NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (peek == NULL)
|
2015-07-23 19:36:38 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
peek = block_Alloc(len);
|
2015-07-23 19:36:38 +02:00
|
|
|
if (unlikely(peek == NULL))
|
|
|
|
return VLC_ENOMEM;
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
peek->i_buffer = 0;
|
2015-07-23 19:36:38 +02:00
|
|
|
}
|
2016-07-24 21:47:01 +02:00
|
|
|
else
|
|
|
|
if (peek->i_buffer < len)
|
2015-07-23 19:36:38 +02:00
|
|
|
{
|
2016-07-24 21:47:01 +02:00
|
|
|
size_t avail = peek->i_buffer;
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
peek = block_TryRealloc(peek, 0, len);
|
2015-07-23 19:36:38 +02:00
|
|
|
if (unlikely(peek == NULL))
|
|
|
|
return VLC_ENOMEM;
|
2015-09-01 17:15:39 +02:00
|
|
|
|
2015-07-23 19:36:38 +02:00
|
|
|
peek->i_buffer = avail;
|
2016-07-24 21:47:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
priv->peek = peek;
|
|
|
|
*bufp = peek->p_buffer;
|
|
|
|
|
|
|
|
while (peek->i_buffer < len)
|
|
|
|
{
|
|
|
|
size_t avail = peek->i_buffer;
|
|
|
|
ssize_t ret;
|
2015-07-23 19:36:38 +02:00
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
ret = vlc_stream_ReadRaw(s, peek->p_buffer + avail, len - avail);
|
2016-07-24 21:47:01 +02:00
|
|
|
if (ret < 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
peek->i_buffer += ret;
|
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
return peek->i_buffer;
|
2015-07-23 19:36:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
block_t *vlc_stream_ReadBlock(stream_t *s)
|
2016-07-19 18:56:58 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2016-07-19 18:56:58 +02:00
|
|
|
block_t *block;
|
|
|
|
|
2016-07-24 21:47:01 +02:00
|
|
|
if (vlc_killed())
|
|
|
|
{
|
|
|
|
priv->eof = true;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-07-19 18:56:58 +02:00
|
|
|
if (priv->peek != NULL)
|
|
|
|
{
|
|
|
|
block = priv->peek;
|
|
|
|
priv->peek = NULL;
|
|
|
|
}
|
2016-07-19 22:34:37 +02:00
|
|
|
else if (priv->block != NULL)
|
|
|
|
{
|
|
|
|
block = priv->block;
|
|
|
|
priv->block = NULL;
|
|
|
|
}
|
2023-03-17 11:48:19 +01:00
|
|
|
else if ((s->ops != NULL && s->ops->stream.block != NULL) || (s->ops == NULL && s->pf_block != NULL))
|
2016-07-19 22:34:37 +02:00
|
|
|
{
|
|
|
|
priv->eof = false;
|
2023-03-17 11:48:19 +01:00
|
|
|
block = (s->ops != NULL ? s->ops->stream.block : s->pf_block)(s, &priv->eof);
|
2016-07-19 22:34:37 +02:00
|
|
|
}
|
2016-07-19 18:56:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
block = block_Alloc(4096);
|
|
|
|
if (unlikely(block == NULL))
|
|
|
|
return NULL;
|
|
|
|
|
2023-03-17 11:48:19 +01:00
|
|
|
ssize_t ret = (s->ops != NULL ? s->ops->stream.read : s->pf_read)(s, block->p_buffer, block->i_buffer);
|
2016-07-24 21:47:01 +02:00
|
|
|
if (ret > 0)
|
2016-07-19 18:56:58 +02:00
|
|
|
block->i_buffer = ret;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
block_Release(block);
|
|
|
|
block = NULL;
|
|
|
|
}
|
2016-07-24 21:47:01 +02:00
|
|
|
|
|
|
|
priv->eof = !ret;
|
2016-07-19 18:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (block != NULL)
|
|
|
|
priv->offset += block->i_buffer;
|
|
|
|
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
uint64_t vlc_stream_Tell(const stream_t *s)
|
2015-08-31 21:19:32 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
const stream_priv_t *priv = stream_priv(s);
|
2015-08-31 21:19:32 +02:00
|
|
|
|
2016-07-19 19:02:22 +02:00
|
|
|
return priv->offset;
|
2015-08-31 21:19:32 +02:00
|
|
|
}
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
bool vlc_stream_Eof(const stream_t *s)
|
2016-07-19 19:28:49 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
const stream_priv_t *priv = stream_priv(s);
|
2016-07-19 19:28:49 +02:00
|
|
|
|
|
|
|
return priv->eof;
|
|
|
|
}
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
int vlc_stream_Seek(stream_t *s, uint64_t offset)
|
2015-09-01 22:26:58 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2015-09-01 22:26:58 +02:00
|
|
|
|
2016-07-19 19:28:49 +02:00
|
|
|
priv->eof = false;
|
|
|
|
|
2015-09-02 17:45:34 +02:00
|
|
|
block_t *peek = priv->peek;
|
|
|
|
if (peek != NULL)
|
|
|
|
{
|
2016-07-19 19:02:22 +02:00
|
|
|
if (offset >= priv->offset
|
|
|
|
&& offset <= (priv->offset + peek->i_buffer))
|
|
|
|
{ /* Seeking within the peek buffer */
|
|
|
|
size_t fwd = offset - priv->offset;
|
2015-09-02 17:45:34 +02:00
|
|
|
|
2016-07-19 19:02:22 +02:00
|
|
|
peek->p_buffer += fwd;
|
|
|
|
peek->i_buffer -= fwd;
|
|
|
|
priv->offset = offset;
|
2015-09-02 17:45:34 +02:00
|
|
|
|
2016-07-19 19:02:22 +02:00
|
|
|
if (peek->i_buffer == 0)
|
|
|
|
{
|
|
|
|
priv->peek = NULL;
|
|
|
|
block_Release(peek);
|
2015-09-02 17:45:34 +02:00
|
|
|
}
|
2016-07-19 19:02:22 +02:00
|
|
|
|
|
|
|
return VLC_SUCCESS;
|
2015-09-02 17:45:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (priv->offset == offset)
|
|
|
|
return VLC_SUCCESS; /* Nothing to do! */
|
|
|
|
}
|
|
|
|
|
2023-03-17 11:48:19 +01:00
|
|
|
int ret;
|
|
|
|
if (s->ops == NULL && s->pf_seek != NULL) {
|
|
|
|
ret = s->pf_seek(s, offset);
|
|
|
|
} else if (s->ops != NULL && s->ops->stream.seek != NULL) {
|
|
|
|
ret = s->ops->stream.seek(s, offset);
|
|
|
|
} else {
|
2015-09-01 22:26:58 +02:00
|
|
|
return VLC_EGENERIC;
|
2023-03-17 11:48:19 +01:00
|
|
|
}
|
2015-09-01 22:26:58 +02:00
|
|
|
|
|
|
|
if (ret != VLC_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
priv->offset = offset;
|
|
|
|
|
|
|
|
if (peek != NULL)
|
|
|
|
{
|
|
|
|
priv->peek = NULL;
|
|
|
|
block_Release(peek);
|
|
|
|
}
|
|
|
|
|
2016-07-19 22:34:37 +02:00
|
|
|
if (priv->block != NULL)
|
|
|
|
{
|
|
|
|
block_Release(priv->block);
|
|
|
|
priv->block = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:50:21 +02:00
|
|
|
return VLC_SUCCESS;
|
2015-09-01 22:26:58 +02:00
|
|
|
}
|
|
|
|
|
2007-04-18 20:55:19 +02:00
|
|
|
/**
|
|
|
|
* Use to control the "stream_t *". Look at #stream_query_e for
|
|
|
|
* possible "i_query" value and format arguments. Return VLC_SUCCESS
|
|
|
|
* if ... succeed ;) and VLC_EGENERIC if failed or unimplemented
|
|
|
|
*/
|
2016-07-20 22:02:54 +02:00
|
|
|
int vlc_stream_vaControl(stream_t *s, int cmd, va_list args)
|
2007-04-18 20:55:19 +02:00
|
|
|
{
|
2022-04-26 15:24:19 +02:00
|
|
|
stream_priv_t *priv = stream_priv(s);
|
2015-07-23 19:36:38 +02:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
2015-09-02 21:48:30 +02:00
|
|
|
case STREAM_SET_TITLE:
|
|
|
|
case STREAM_SET_SEEKPOINT:
|
|
|
|
{
|
2023-01-30 16:49:28 +01:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (s->ops != NULL && cmd == STREAM_SET_TITLE) {
|
|
|
|
int title = va_arg(args, int);
|
|
|
|
ret = s->ops->set_title(s, title);
|
|
|
|
} else if (s->ops != NULL && cmd == STREAM_SET_SEEKPOINT) {
|
|
|
|
int seekpoint = va_arg(args, int);
|
|
|
|
ret = s->ops->set_seek_point(s, seekpoint);
|
|
|
|
} else {
|
|
|
|
ret = s->pf_control(s, cmd, args);
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:48:30 +02:00
|
|
|
if (ret != VLC_SUCCESS)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
priv->offset = 0;
|
|
|
|
|
|
|
|
if (priv->peek != NULL)
|
|
|
|
{
|
|
|
|
block_Release(priv->peek);
|
|
|
|
priv->peek = NULL;
|
|
|
|
}
|
2016-07-19 22:34:37 +02:00
|
|
|
|
|
|
|
if (priv->block != NULL)
|
|
|
|
{
|
|
|
|
block_Release(priv->block);
|
|
|
|
priv->block = NULL;
|
|
|
|
}
|
|
|
|
|
2015-09-02 21:48:30 +02:00
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
2015-07-23 19:36:38 +02:00
|
|
|
}
|
2023-01-30 16:49:28 +01:00
|
|
|
|
|
|
|
if (s->ops == NULL)
|
|
|
|
return s->pf_control(s, cmd, args);
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case STREAM_CAN_SEEK:
|
|
|
|
{
|
|
|
|
bool *can_seek = va_arg(args, bool *);
|
|
|
|
if (s->ops->can_seek != NULL) {
|
|
|
|
*can_seek = s->ops->can_seek(s);
|
|
|
|
} else {
|
|
|
|
*can_seek = false;
|
|
|
|
}
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
case STREAM_CAN_FASTSEEK:
|
|
|
|
{
|
|
|
|
bool *can_fastseek = va_arg(args, bool *);
|
|
|
|
if (s->ops->stream.can_fastseek != NULL) {
|
|
|
|
*can_fastseek = s->ops->stream.can_fastseek(s);
|
|
|
|
} else {
|
|
|
|
*can_fastseek = false;
|
|
|
|
}
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
case STREAM_CAN_PAUSE:
|
|
|
|
{
|
|
|
|
bool *can_pause = va_arg(args, bool *);
|
|
|
|
if (s->ops->can_pause != NULL) {
|
|
|
|
*can_pause = s->ops->can_pause(s);
|
|
|
|
} else {
|
|
|
|
*can_pause = false;
|
|
|
|
}
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
case STREAM_CAN_CONTROL_PACE:
|
|
|
|
{
|
|
|
|
bool *can_control_pace = va_arg(args, bool *);
|
|
|
|
if (s->ops->can_control_pace != NULL) {
|
|
|
|
*can_control_pace = s->ops->can_control_pace(s);
|
|
|
|
} else {
|
|
|
|
*can_control_pace = false;
|
|
|
|
}
|
|
|
|
return VLC_SUCCESS;
|
|
|
|
}
|
|
|
|
case STREAM_GET_SIZE:
|
|
|
|
if (s->ops->stream.get_size != NULL) {
|
|
|
|
uint64_t *size = va_arg(args, uint64_t *);
|
|
|
|
return s->ops->stream.get_size(s, size);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_PTS_DELAY:
|
|
|
|
if (s->ops->get_pts_delay != NULL) {
|
|
|
|
vlc_tick_t *pts_delay = va_arg(args, vlc_tick_t *);
|
|
|
|
return s->ops->get_pts_delay(s, pts_delay);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_TITLE_INFO:
|
|
|
|
if (s->ops->stream.get_title_info != NULL) {
|
|
|
|
input_title_t ***title_info = va_arg(args, input_title_t ***);
|
|
|
|
int *unk = va_arg(args, int *);
|
|
|
|
return s->ops->stream.get_title_info(s, title_info, unk);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_TITLE:
|
2023-03-13 13:35:51 +01:00
|
|
|
if (s->ops->stream.get_title != NULL) {
|
2023-01-30 16:49:28 +01:00
|
|
|
unsigned *title = va_arg(args, unsigned *);
|
2023-03-13 13:35:51 +01:00
|
|
|
return s->ops->stream.get_title(s, title);
|
2023-01-30 16:49:28 +01:00
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_SEEKPOINT:
|
2023-03-13 10:47:39 +01:00
|
|
|
if (s->ops->stream.get_seekpoint != NULL) {
|
2023-01-30 16:49:28 +01:00
|
|
|
unsigned *seekpoint = va_arg(args, unsigned *);
|
2023-03-13 10:47:39 +01:00
|
|
|
return s->ops->stream.get_seekpoint(s, seekpoint);
|
2023-01-30 16:49:28 +01:00
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_META:
|
|
|
|
if (s->ops->get_meta != NULL) {
|
|
|
|
vlc_meta_t *meta = va_arg(args, vlc_meta_t *);
|
|
|
|
return s->ops->get_meta(s, meta);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_CONTENT_TYPE:
|
|
|
|
if (s->ops->stream.get_content_type != NULL) {
|
|
|
|
char **content_type = va_arg(args, char **);
|
|
|
|
return s->ops->stream.get_content_type(s, content_type);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_SIGNAL:
|
|
|
|
if (s->ops->get_signal != NULL) {
|
|
|
|
double *quality = va_arg(args, double *);
|
|
|
|
double *strength = va_arg(args, double *);
|
|
|
|
return s->ops->get_signal(s, quality, strength);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_TAGS:
|
|
|
|
if (s->ops->stream.get_tags != NULL) {
|
|
|
|
const block_t **block = va_arg(args, const block_t **);
|
|
|
|
return s->ops->stream.get_tags(s, block);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_TYPE:
|
|
|
|
if (s->ops->get_type != NULL) {
|
|
|
|
int *type = va_arg(args, int *);
|
|
|
|
return s->ops->get_type(s, type);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_GET_PRIVATE_ID_STATE:
|
|
|
|
if (s->ops->stream.get_private_id_state != NULL) {
|
|
|
|
int priv_data = va_arg(args, int);
|
|
|
|
bool *selected = va_arg(args, bool *);
|
|
|
|
return s->ops->stream.get_private_id_state(s, priv_data, selected);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_SET_PAUSE_STATE:
|
|
|
|
if (s->ops->set_pause_state != NULL) {
|
|
|
|
bool pause_state = (bool)va_arg(args, int);
|
|
|
|
return s->ops->set_pause_state(s, pause_state);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_SET_RECORD_STATE:
|
|
|
|
if (s->ops->stream.set_record_state != NULL) {
|
|
|
|
bool record_state = (bool)va_arg(args, int);
|
|
|
|
const char *dir_path = NULL;
|
|
|
|
const char *ext = NULL;
|
|
|
|
if (record_state) {
|
|
|
|
dir_path = va_arg(args, const char *);
|
|
|
|
ext = va_arg(args, const char *);
|
|
|
|
}
|
|
|
|
return s->ops->stream.set_record_state(s, record_state, dir_path, ext);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_SET_PRIVATE_ID_STATE:
|
|
|
|
if (s->ops->stream.set_private_id_state != NULL) {
|
|
|
|
int priv_data = va_arg(args, int);
|
|
|
|
bool selected = (bool)va_arg(args, int);
|
|
|
|
return s->ops->stream.set_private_id_state(s, priv_data, selected);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
case STREAM_SET_PRIVATE_ID_CA:
|
|
|
|
if (s->ops->stream.set_private_id_ca != NULL) {
|
|
|
|
void *payload = va_arg(args, void *);
|
|
|
|
return s->ops->stream.set_private_id_ca(s, payload);
|
|
|
|
}
|
|
|
|
return VLC_EGENERIC;
|
|
|
|
default:
|
|
|
|
vlc_assert_unreachable();
|
|
|
|
}
|
2007-04-18 20:55:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-08-31 18:59:22 +02:00
|
|
|
* Read data into a block.
|
|
|
|
*
|
|
|
|
* @param s stream to read data from
|
|
|
|
* @param size number of bytes to read
|
|
|
|
* @return a block of data, or NULL on error
|
|
|
|
@ note The block size may be shorter than requested if the end-of-stream was
|
|
|
|
* reached.
|
2007-04-18 20:55:19 +02:00
|
|
|
*/
|
2016-07-20 22:02:54 +02:00
|
|
|
block_t *vlc_stream_Block( stream_t *s, size_t size )
|
2007-04-18 20:55:19 +02:00
|
|
|
{
|
2015-08-31 18:59:22 +02:00
|
|
|
if( unlikely(size > SSIZE_MAX) )
|
|
|
|
return NULL;
|
2007-04-18 20:55:19 +02:00
|
|
|
|
2015-08-31 18:59:22 +02:00
|
|
|
block_t *block = block_Alloc( size );
|
|
|
|
if( unlikely(block == NULL) )
|
|
|
|
return NULL;
|
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
ssize_t val = vlc_stream_Read( s, block->p_buffer, size );
|
2015-08-31 18:59:22 +02:00
|
|
|
if( val <= 0 )
|
2007-04-18 20:55:19 +02:00
|
|
|
{
|
2015-08-31 18:59:22 +02:00
|
|
|
block_Release( block );
|
|
|
|
return NULL;
|
2007-04-18 20:55:19 +02:00
|
|
|
}
|
2015-08-31 18:59:22 +02:00
|
|
|
|
|
|
|
block->i_buffer = val;
|
|
|
|
return block;
|
2007-04-18 20:55:19 +02:00
|
|
|
}
|
2012-01-07 01:14:03 +01:00
|
|
|
|
2016-07-20 22:02:54 +02:00
|
|
|
int vlc_stream_ReadDir( stream_t *s, input_item_node_t *p_node )
|
2014-06-21 15:55:10 +02:00
|
|
|
{
|
2023-03-17 11:48:19 +01:00
|
|
|
assert(s->pf_readdir != NULL || (s->ops != NULL && s->ops->stream.readdir != NULL));
|
|
|
|
return (s->ops != NULL ? s->ops->stream.readdir : s->pf_readdir)( s, p_node );
|
2014-06-21 15:55:10 +02:00
|
|
|
}
|