Commit Graph

319 Commits

Author SHA1 Message Date
Loïc Branstett f93de3ef23 stream/demux: move remaining callbacks to their respective ops struct
This commit moves the remaining callbacks of stream/demux: pf_read/
pf_block/pf_seek/pf_readdir and pf_demux into their operations table,
aiming at unifying all the callbacks under a unique place.
This is a follow-up to the introduction of typed controls callbacks
for stream and demux.

Like for the typed controls callbacks if no operation is provided
(ie, stream_t/demux_t.ops is NULL) by a module, the legacy pf_* will be
used instead as a fallback.

The commit doesn't migrate any of modules yet.
2023-03-24 10:51:36 +00:00
Loïc 6baee5a410 stream: move get_title typed control to stream specific section 2023-03-16 14:20:37 +00:00
Loïc 21f9f3818c stream: move get_seekpoint typed control to specific stream section
This is done because the type is different from stream and demux.
2023-03-16 14:20:37 +00:00
Loïc f77921f427 stream: introduce typed operations for stream
This commit introduce a typed virtual table for operations on stream,
aiming at replacing the legacy pf_control() callback which is using
va_list. As a counterpart to the typed virtual table, typed methods
are also introduce.

The operations can be implemented by the modules directly right now
and will be used when possible. This is done to provide type safety
at every level.

When no operation is provided (ie, stream_t.ops is NULL) by a module
implementation, the legacy pf_control will be used instead as a
fallback.

The commit doesn't migrate any of access/stream_filter/… modules yet.
The commit also doesn't introduce the demux specific callbacks yet.
2023-03-11 18:01:48 +00:00
Thomas Guillem 3d2f691ebc stream: use container_of 2022-04-28 16:30:00 +00:00
Lyndon Brown a9dd4b1452 stream: add missing explicit initialisation
(matching the order of attributes in the struct)

the object is allocated with `calloc()` via `vlc_custom_create()` but
despite this explicit allocation is wanted.
2022-01-13 15:42:21 +00:00
Lyndon Brown cb54d4d5c4 Revert "stream: remove pointless & incomplete initialisation"
This reverts commit 830ea36e70.

as requested in follow-up discussion in !1104.

(actually this is now a partial revert - the change to the return line has
been left in place per review request in !1193).
2022-01-13 15:42:21 +00:00
Lyndon Brown 830ea36e70 stream: remove pointless & incomplete initialisation
`vlc_custom_create()` uses `calloc()` to allocate the memory, so
initialising all of the attributes individually to null/0/false is
unnecessary.

the initialisation was not even complete, missing all of these:
 - s->psz_name
 - s->psz_location
 - s->b_preparsing
 - s->out
 - s->pf_demux
2022-01-10 07:03:38 +00:00
Lyndon Brown d81e20055e demux: abort module loading upon search string creation failure
if in "any" mode and falling back to an extension based match, and if the
`asprintf()` call fails to create the extension based shortcut search
string, the consensus is that it should give up rather than proceed to try
an "any" based demux module load.

note that the `modbuf = NULL` statement was just resetting the undefined
state of the variable from the failed `asprintf()` call to ensure that the
later `free(modbuf)` was valid. it is not needed now that we go down the
error path.

note, the init of `s->psz_filepath` in `vlc_stream_CustomNew()` is not
strictly necessary to avoid `free()` on an initialised attribute, since
`calloc()` is actually involved in the object creation - much of the
initialisation done in `vlc_stream_CustomNew()` is actually redundant.
2022-01-10 07:03:38 +00:00
Hugo Beauzée-Luyssen 3b670ad92d input: stream: Avoid VLA 2020-12-11 13:02:48 +01:00
Pierre Ynard aa4996021d stream_ReadLine: probe data exponentially instead of linearly
This reduces the number of buffer reallocations performed for long
lines, turning the function's complexity from quadratic to linear. The
line length limit remains unchanged.
2020-10-27 09:01:25 +01:00
Pierre Ynard a06be413dd stream_ReadLine: don't discard unreturned data on error
Upon error, data already consumed from the stream could be discarded
and permanently lost for the caller. This was just bad, and notably
precluded recovery from errors. Instead, data is now preserved within
peek buffers until a line can be successfully returned.

Peak memory usage remains almost identical, while the number of
allocations is halved for long lines. For UTF-16 streams, memory usage
is reduced as needless buffer allocations and copies are eliminated.
2020-10-27 08:59:57 +01:00
Pierre Ynard 6da1ad5264 stream_ReadLine: simplify flow and variable types
No functional change
2020-10-27 08:58:02 +01:00
Pierre Ynard 4a0582e475 stream_ReadLine: log error when failing on line too long 2020-10-27 08:57:08 +01:00
Pierre Ynard 5cfcbd7c18 stream_ReadLine: move BOM detection outside and before reading loop
No functional change
2020-10-27 08:56:06 +01:00
Pierre Ynard 65f6b1b719 stream_ReadLine: properly discard incomplete UTF-16 sequences at EOF
Lone-byte incomplete UTF-16 sequences before EOF, in some cases such as
a final line consisting only of it, would never get actually consumed
from the stream, preventing it from ever properly reaching EOF.

This also avoids flooding the logs with one warning per stream line
towards the end of the stream, and then printing an unspecific
conversion error: those are replaced by one clear and explicit error
message.
2020-10-27 08:54:24 +01:00
Pierre Ynard 4a0c695ab3 stream_ReadLine: reset iconv state on conversion error
Tested against UTF-16 lone surrogates, for which it seems to make no
difference
2020-10-27 08:48:23 +01:00
Pierre Ynard 520e79aa6e stream_ReadLine: don't gratuitiously close iconv handle on unrelated error
The only errors after which this was called were memory allocation
errors, lines too long, or failing to open the handle itself, so
obviously there is no reason to want to close it there; it already gets
closed in the proper place when the stream is destroyed.

Even worse, it left the handle missing if vlc_stream_ReadLine() was
called again, and would result in text conversion constantly failing and
no output getting returned anymore, rendering the rest of the stream
unusable through this API and precluding any error recovery.
2020-10-27 08:44:29 +01:00
Pierre Ynard 097f4e0169 stream_ReadLine: properly reset text encoding parameters
Only the iconv handle was correctly reset, potentially leading again to
wrong or inconsistent parameters.
2020-10-03 12:05:05 +02:00
Pierre Ynard f21515fc18 stream_ReadLine: don't set inconsistent encoding parameters on error 2020-10-03 12:02:38 +02:00
Pierre Ynard 1a95477554 stream_ReadLine: fix end of line detection on big-endian UTF-16
Lines would be split on non-breaking spaces (0x00A0) instead of line
feeds (0x000A).
2020-09-17 06:09:06 +02:00
Rémi Denis-Courmont 07b7122857 objects: introduce vlc_object_delete()
Objects have one strong reference held by their "owner", and zero or
more weak references generated by vlc_object_hold() et al. This
provides a separate function to remove the strong reference than
vlc_object_release() to remove weak ones.

With this sole change, this is really only an annotation though.
2019-03-06 22:53:24 +02:00
Steve Lhomme 5363279805 remove the $Id$ in the source code 2019-01-17 12:21:18 +01:00
Thomas Guillem 6b96ade7dd stream: replace input_thread_t by input_item_t
This will prevent all demuxers/access/streams to mess with the input_thread_t
state.
2018-07-20 17:23:03 +02:00
Rémi Denis-Courmont fc7362222b access: develop stream_FilterAutoNew() calls
Moves calls to stream_FilterAutoNew() out of stream_AccessNew().
No overall functional changes.
2018-04-16 18:08:07 +03:00
Rémi Denis-Courmont 7f46d83bfb stream: remove p_module 2018-04-06 20:45:10 +03:00
Rémi Denis-Courmont c89e49dede input: add vlc_stream_CustomNew() and vlc_stream_Private()
These two functions allow setting the object type name for the stream
object, and allocating type-specific private data.
2018-04-06 20:05:21 +03:00
Rémi Denis-Courmont ab6c0897df stream: clean up vlc_stream_ReadDir() documentation 2018-03-31 17:59:20 +03:00
Rémi Denis-Courmont e4f6b4480b stream: add assertion 2018-03-31 17:59:20 +03:00
Rémi Denis-Courmont 9c6cde9415 access: pass ES output to access_New() 2018-03-29 18:22:38 +03:00
Rémi Denis-Courmont 0d6cb7a602 include: remove <vlc_memory.h>
This only ever contained a single helper function.
2018-02-11 21:37:10 +02:00
Rémi Denis-Courmont 7902c7a656 stream: rename p_source to s (refs #18504) 2017-12-02 23:23:56 +02:00
Rémi Denis-Courmont 297e6f4fd4 stream: fix off-by-one
One byte is (potentially) needed to append the final nul.
2017-11-12 15:24:15 +02:00
Rémi Denis-Courmont fe118244f4 input: fix iconv handle leak
This occurred if a UTF-16 text stream was rewound to the beginning and
read again.
2017-06-21 21:12:07 +03:00
Rémi Denis-Courmont a672ea060e input: handle error in stream_ReadLine() 2017-06-21 21:12:03 +03:00
Rémi Denis-Courmont 27849047fc vlc_stream_ReadLine: fix trimming 8-bits lines (fixes #18364)
The conversion from UTF-16 to UTF-8 could (until a few days ago) fail
before the end. In that case, the appended nul terminator would not be
converted. A nul terminator is anyway always appended after conversion
and trimming.

If conversion failed on the first character, that nul terminator would
be written at a negative offset, leading to heap buffer "underflow" and
memory corruption. This was fixed but lead to a mismatch in the value of
i_lines depending on the character width.

This change removes the useless pre-conversion nul terminator, and thus
makes trimming work again with single byte character width work. This
fixes reading text files formatted with MS-DOS line endings.
2017-05-26 22:37:31 +03:00
Rémi Denis-Courmont 32ff0bbcad vlc_stream_ReadLine: fix trimming
Removal of CR or LF final characters relied on the off-by-one bug fixed
in the previous changest, and no longer works. This adjusts it
accordingly.
2017-05-24 22:07:05 +03:00
Rémi Denis-Courmont dbb8a1891f vlc_stream_ReadLine: fix off-by-one
Do not erase the last converted byte. This bug has apparently existed
ever since UTF-16 support was added.

If the conversion fails, this bug resulted in a heap underflow (writing
zero right before the beginning of the buffer).
2017-05-24 20:01:40 +03:00
Rémi Denis-Courmont 0379cf77c9 vlc_stream_ReadLine(): improve error reporting 2017-05-24 20:01:39 +03:00
Filip Roséen a1ae9f4b46 vlc_stream: add vlc_stream_NewMRL
Signed-off-by: Hugo Beauzée-Luyssen <hugo@beauzee.fr>
2017-05-16 17:51:17 +02:00
Rémi Denis-Courmont dc513b6d37 stream: do not pass NULL buffer to access module
access_t.pf_read did not expect a NULL output pointer before the merge
of access_t and stream_t. For files, this caused an EFAULT error, but
for other input types, it would likely crash.
2017-02-07 21:51:48 +02:00
Filip Roséen e4fbdcebeb stream: rename vlc_stream_NewMRL to vlc_stream_NewURL
The function does not open MRLs, as correctly described in its
documentation, as such it is rather unfortunate that its name uses MRL
instead of URL (especially given that it cannot handle MRLs).

These changes are simply renaming all occurrences of the function, so
that the behavior of the function is properly reflected by its name.

Signed-off-by: Thomas Guillem <thomas@gllm.fr>
2016-12-06 15:57:19 +01:00
Rémi Denis-Courmont 3bf8a8ec60 stream: assert that read size is well defined
The result of a read operation is a signed size_t, and cannot be
negative (except on error). Thus reading more than SSIZE_MAX bytes at
once is not well defined.

(Note: POSIX marks it as implementation-defined, and we cannot rely on
 much given the different implementations.)

In practice, this is not really a limitation for regular reads as
allocating a contiguous output buffer of more than SSIZE_MAX bytes is
essentially impossible. It can however be a problem when skipping data
(buffer pointer is NULL), especially on 32-bits platforms.

To skip such large amount of data, seeking is recommended instead,
e.g.:

    vlc_stream_Seek(s, vlc_stream_Tell() + skip);

instead of:

    vlc_stream_Read(s, NULL, skip);
2016-10-31 10:02:44 +02:00
Filip Roséen fd3e08b35f input/stream: make stream_ReadLine work with block-based streams
The if-statement in question prevents stream_ReadLine to work if invoked
with a block-based stream, as such the condition has now been altered to
only return immediately if the source stream does not have neither of
pf_read and pf_block.

Signed-off-by: Rémi Denis-Courmont <remi@remlab.net>
2016-07-25 22:10:40 +02:00
Rémi Denis-Courmont cec507e872 stream: revector 2016-07-24 22:47:18 +03:00
Rémi Denis-Courmont 38be0d228c stream: merge access_t and stream_t
They were mostly identical, with just a few extra fields in access_t.
Merging them will allow removing the dummy stream_Access layer.
2016-07-21 22:27:00 +03:00
Rémi Denis-Courmont b75462c33e stream: add vlc_stream_ReadPartial()
This is a variant of vlc_stream_Read(), such that it only waits for
some bytes (i.e. more than zero) rather than the full requested bytes
count.
2016-07-21 22:27:00 +03:00
Rémi Denis-Courmont e77eb3bdb2 stream: use same pf_read return value as access
Accesses return -1 to try again; stream filters returned -1 for fatal
errors. This switches stream filters to 0 for fatal errors.
2016-07-21 22:27:00 +03:00
Rémi Denis-Courmont 312d198438 stream: stream_ -> vlc_stream_ 2016-07-21 22:26:57 +03:00
Rémi Denis-Courmont 9e8c9e95cf stream: remove stream_CustomNew() 2016-07-21 19:59:25 +03:00