As reported by sparse:
drivers/media/test-drivers/vidtv/vidtv_ts.h:47:47: warning: array of flexible structures
drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54: warning: incorrect type in argument 3 (different base types)
drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54: expected unsigned short [usertype] service_id
drivers/media/test-drivers/vidtv/vidtv_channel.c:458:54: got restricted __be16 [usertype] service_id
drivers/media/test-drivers/vidtv/vidtv_s302m.c:471 vidtv_s302m_encoder_init() warn: possible memory leak of 'e'
Address such warnings.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Some functions has a different name between their prototypes
and the corresponding kernel-doc markups.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Currently the call to vidtv_psi_pat_table_destroy frees the object
m->si.pat however m->si.pat->num_pmt is being accessed after the
free. Fix this by destroying m->si.pat after the m->si.pmt_secs[]
objects have been freed.
Addresses-Coverity: ("Read from pointer after free")
Reported-by: Cengiz Can <cengiz@kernel.wtf> # sent a similar fix about the same time
Fixes: 039b7caed1 ("media: vidtv: add a PID entry for the NIT table")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Avoid initializing the structs multiple times and pass the
PAT struct as a pointer, instead of a var.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
- Pass struct header_write_args as a pointer, instead of
passing as a var;
- Initialize the psi_args struct only once.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This function initializes the psi_args twice, and receives
a struct, instead of a pointer to a struct.
Clean it up.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Cleanup the table_section_crc32_write_into() function
by initializing struct psi_write_args only once and by
passing the args as a pointer.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The function vidtv_psi_ts_psi_write_into() initializes the
ts_header fields several times, and receives a struct
as argument, instead of using a pointer to struct.
Cleanup the function, in order to reduce its stack usage
and to avoid initializing the ts_header multiple times.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The current event is using an undefined date. Instead, it
should be the timestamp when the EIT table was generated.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The service_id there should be equal to the one used
on other tables, otherwise, EIT entries won't be valid.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As the service currently broadcasts just audio, change the
service type to reflect that.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
On normal TS streams, the NIT table has its own entry at PAT,
but not at PMT.
While here, properly handle alloc problems when creating
PMT entries.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The EIT header ID field should not contain the network ID, but,
instead, the service_id of the program described at EIT.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As defined at ETSI TS 101 162, original network IDs up to 0xfebf
are reserved for registration at dvb.org.
Let's use, instead, an original network ID at the range
0xff00-0xffff, as this is for private temporary usage.
As the same value is also used for the network ID,
the range 0xff01-0xffff also fits better, as values
lower than that depend if the network is used for
satellite, terrestrial, cable of CI.
While here, move the TS ID to the bridge code, where it
is used, and change its value, as it was identical to
the value previously used by network ID. While we could
keep the same value, let's change it, just to make easier
to check for the new code while reading it with DVB tools
like dvbinspector.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Place some text at EIT data, and use ISO 8859-15 encoding for
the German letter "ü" (u mit umlat) letter.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Initialize the destination buffer/size and the initial
offset when creating the local var.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Instead of first zeroing all fields at the mux structs and
then filling, do some initialization for the const data
when they're created.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Right now, there's no need to access the length of some
tables. So, drop the unused functions.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Do some cleanups at the coding style of the driver:
- remove "inline" declarations;
- use reverse xmas-tree for local var declarations;
- Adjust some indent to avoid breaking 80-cols;
- Cleanup some comments.
No functional changes.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Minimize the number of data copies and initialization at
the code, passing them as pointers instead of duplicating
the data.
The only case where we're keeping the data copy is at
vidtv_pes_write_h(), as it needs a copy of the passed
arguments. On such case, we're being more explicit.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Initialize the fields of the arguments directly when
declaring it, and pass the args as a pointer, instead of
copying them.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The sheet music used to generate the tones had a few
polyphonic notes. Due to that, its conversion to a
tones sequence had a few errors.
Also, due to a bug at the tone generator, it was missing
the pause at the initial compass.
Fix them.
While here, reduce the compass to 100bpm.
The music was converted from a Music XML file using
this small script:
<snip>
my $count = 0;
my $silent = 0;
my $note;
my $octave;
print "\t";
while (<>) {
$note = $1 if (m,\<step\>(.*)\</step\>,);
$octave = "_$1" if (m,\<octave\>(.*)\</octave\>,);
if (m,\<alter\>1\</alter\>,) {
$note .= "S";
$sharp = 1;
}
if (m,\<rest/\>,) {
$note = "SILENT";
$silent = 1;
}
if (m,\<duration\>(.*)\</duration\>,) {
printf "{ NOTE_${note}${octave}, %d},", $1 * 128 / 480;
$count++;
if ($silent || $count >= 3) {
print "\n\t";
$count = 0;
$silent = 0;
} else {
print " ";
print " " if (!$sharp);
}
$sharp = 0;
$note = "";
$octave = "";
};
};
print "\n";
</snip>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The tone generator logic were repeating the song after the
first silent. There's also a wrong logic at the note
offset calculus, which may create some noise.
Fix it.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
While the original plan was to use the first movement of
the 5th Symphony, it was opted to use the Für Elise song,
instead.
Fix it.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The Linux stack is too short. So, using recursive functions
is a very bad idea. Convert those into non-recursive ones.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Currently, there are not checks if something gets bad during
memory allocation: it will simply use NULL pointers and
crash.
Add error path at the logic which allocates memory for the
MPEG-TS generator code, propagating the errors up to the
vidtv_bridge. Now, if something wents bad, start_streaming
will return an error that userspace can detect:
ERROR DMX_SET_PES_FILTER failed (PID = 0x2000): 12 Cannot allocate memory
and the driver doesn't crash.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
- Place the includes on alphabetical order;
- get rid of asm/byteorder.h;
- add bug.h at vidtv_s302m.c, as it is needed by
inux/fixp-arith.h
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Some variables were only assigned once but were used in while
loops as if they had been updated at every iteration. Fix this.
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
A few fields used only by the tone generator in the s302m encoder
are stored in struct vidtv_encoder. Move them into
struct vidtv_s302m_ctx instead. While we are at it: fix a
checkpatch warning for long lines.
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The code to append a descriptor to the end of a chain is repeated
throughout the psi generator code. Extract it into its own helper
function to avoid cluttering.
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Implement an Event Information Table (EIT) as per EN 300 468
5.2.4.
The EIT provides information in chronological order regarding
the events contained within each service.
For now only present event information is supported.
[mchehab+huawei@kernel.org: removed an extra blank line]
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Add a Network Information Table (NIT) as specified in ETSI EN 300 468.
This table conveys information relating to the physical organization of
the multiplexes carried via a given network and the characteristics of
the network itself.
It is conveyed in the output of vidtv as packets with TS PID of 0x0010
[mchehab+huawei@kernel.org: removed an extra blank line]
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The same constant (0xffffffff) is used in three different functions.
Extract it into a #define to avoid repetition.
Signed-off-by: Daniel W. S. Almeida <dwlsalmeida@gmail.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Neither Vlc nor Gstreamer likes the PES_scrambling_control bits.
In the case of GST, this can be seen with:
$ GST_DEBUG=2 LANG=C gst-play-1.0 pcm_audio.ts
...
0:00:00.097973439 12308 0x55f7ddd155e0 WARN pesparser pesparse.c:411:mpegts_parse_pes_header: Wrong '0x10' marker before PES_scrambling_control (0x40)
0:00:00.097987026 12308 0x55f7ddd155e0 WARN tsdemux tsdemux.c:2314:gst_ts_demux_parse_pes_header: Error parsing PES header. pid: 0x111 stream_type: 0x6
...
So, change, it. After such change, the stream now plays
fine with Vlc, Gstreamer, ffmpeg - and with programs
that use such libraries, like Kaffeine.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
When compared with a stream generated via ffmpeg, it can be
noticed that the PES doesn't contain any PCR info. That could
cause problems with userspace decoding. So, rewrite the
logic that fills the adaptation info, in order to allow it
to add PCR frames without breaking frame alignment.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Instead of passing struct pes_ts_header_write_args fields as
function parameters, just pass a pointer to the struct.
That would allow adding more args without needing to change
the function prototype.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
In order to better test userspace applications, add an encoding
for the strings. The original channel string is also too big.
As we're just playing the first compasses of the 5th Beethoven
Symphony, change the service name to just "Beethoven". Also,
add a provider's name. For such purpose, let's point it to
the Linux media community website.
With such changes, the SDT table now looks more like one got
from a real digital TV channel:
SDT
| table_id 0x42
| section_length 44
| one 2
| zero 1
| syntax 1
| transport_stream_id 1860
| current_next 1
| version 0
| one2 3
| section_number 0
| last_section_number 0
| network_id 65281
| reserved 255
|\
|- service 0x0880
| EIT schedule 0
| EIT present following 0
| free CA mode 0
| running status 4
| descriptor length 27
| 0x48: service_descriptor
| service type 1
| provider 'LinuxTV.org'
| name 'Beethoven'
|_ 1 services
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
There's no reason to use static vars to store PSI version
numbers.
Also, currently, version numbers are starting with 0x01,
because there's a code being called that increases it to
1 for all table initializer code, as the code may support
dynamic changes at the PS tables on some future.
So, let's just initialize them to 0x1f, in order for the
versions to be reported as starting from 0.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This field should point to the network ID, and has different
ranges for cable, terrestrial or satellite. It also has
an special range for temporary private usage.
For now, let's use the temporary private one. Once the
Network Information Table (NIT) gets added, this should be
reviewed.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Changeset 870e350d4e ("media: vidtv: get rid of ENDIAN_BITFIELD nonsense")
was incomplete. There are still some wrong endannes logic at
the driver. Get rid of them.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
There's no need to have a check when setting timing.past_jiffies,
as we can simply do the initialization earlier at vidtv_mux_init().
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
The CSC API (Colorspace conversion) allows userspace to try
to configure the colorspace, transfer function, Y'CbCr/HSV encoding
and the quantization for capture devices. This patch adds support
to the CSC API in vivid.
Using the CSC API, userspace is allowed to do the following:
- Set the colorspace.
- Set the xfer_func.
- Set the ycbcr_enc function for YUV formats.
- Set the hsv_enc function for HSV formats
- Set the quantization for YUV and RGB formats.
Signed-off-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
As warned by smatch:
drivers/media/test-drivers/vidtv/vidtv_psi.c:93 vidtv_psi_update_version_num() warn: impossible condition '(h->version > 32) => (0-31 > 32)'
h_version is declared as:
u8 version:5;
Meaning that its value ranges from 0 to 31. Incrementing 31 on such
data will overflow to zero, as expected.
So, just drop the uneeded overflow check.
While here, use "foo++" instead of "++foo", as this is a much
more common pattern.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
There's no need to use u64 over there. In a matter of fact,
the div is not even needed, as it is multiplying by 1000 and
dividing by 1000.
So, simplify the logic.
While here, constrain the buffer size to a certain range
(between the current value and 10 times it)
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>