Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
24f8eb1b
Commit
24f8eb1b
authored
Apr 29, 2020
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented simple experimental mpeg transport stream PCR read/write.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
3e429485
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
0 deletions
+72
-0
mpegts.cc
src/mpegts.cc
+66
-0
mpegts.hh
src/mpegts.hh
+2
-0
testmpegts.cc
src/testmpegts.cc
+4
-0
No files found.
src/mpegts.cc
View file @
24f8eb1b
...
...
@@ -18,6 +18,7 @@
#include <array>
#include <regex>
#include <inttypes.h>
#include "utils.hh"
#include "mpegts.hh"
...
...
@@ -110,6 +111,44 @@ public:
{
return
m_data
;
}
bool
has_pcr
()
{
unsigned
char
adapt
=
(
m_data
[
3
]
>>
4
)
&
0x03
;
if
(
adapt
==
1
)
return
false
;
unsigned
char
adapt_len
=
m_data
[
4
];
return
adapt_len
&&
(
m_data
[
5
]
&
0x10
);
}
uint64_t
pcr
()
{
uint64_t
pcr
=
0
;
unsigned
char
*
buff
=
&
m_data
[
6
];
pcr
|=
buff
[
0
]
<<
25
;
pcr
|=
buff
[
1
]
<<
17
;
pcr
|=
buff
[
2
]
<<
9
;
pcr
|=
buff
[
3
]
<<
1
;
pcr
|=
buff
[
4
]
>>
7
;
pcr
*=
300
;
uint64_t
ext
=
((
buff
[
4
]
&
1
)
<<
8
)
|
buff
[
5
];
pcr
+=
ext
;
return
pcr
;
}
void
patch_pcr
(
uint64_t
pcr
)
{
unsigned
char
*
buff
=
&
m_data
[
6
];
int64_t
pcr_low
=
pcr
%
300
,
pcr_high
=
pcr
/
300
;
*
buff
++
=
pcr_high
>>
25
;
*
buff
++
=
pcr_high
>>
17
;
*
buff
++
=
pcr_high
>>
9
;
*
buff
++
=
pcr_high
>>
1
;
*
buff
++
=
pcr_high
<<
7
|
pcr_low
>>
8
|
0x7e
;
*
buff
++
=
pcr_low
;
}
};
Error
...
...
@@ -274,3 +313,30 @@ TSReader::entries()
}
int
pcr
(
const
string
&
filename
,
const
string
&
outname
,
double
d
)
{
FILE
*
infile
=
fopen
(
filename
.
c_str
(),
"r"
);
ScopedFile
infile_s
(
infile
);
FILE
*
outfile
=
fopen
(
outname
.
c_str
(),
"w"
);
ScopedFile
outfile_s
(
outfile
);
while
(
!
feof
(
infile
))
{
TSPacket
p
;
Error
err
;
bool
read_ok
=
p
.
read
(
infile
,
err
);
if
(
!
read_ok
)
{
if
(
err
)
return
err
;
}
if
(
p
.
has_pcr
())
{
printf
(
"%"
PRIx64
" %f
\n
"
,
p
.
pcr
(),
p
.
pcr
()
*
1e3
/
27e6
);
p
.
patch_pcr
((
p
.
pcr
()
*
1e3
/
27e6
+
d
)
/
(
1e3
/
27e6
));
}
p
.
write
(
outfile
);
}
return
0
;
}
src/mpegts.hh
View file @
24f8eb1b
...
...
@@ -52,4 +52,6 @@ public:
Error
process
(
const
std
::
string
&
in_name
,
const
std
::
string
&
out_name
);
};
int
pcr
(
const
std
::
string
&
filename
,
const
std
::
string
&
outname
,
double
time_offset_ms
);
#endif
/* AUDIOWMARK_MPEGTS_HH */
src/testmpegts.cc
View file @
24f8eb1b
...
...
@@ -52,6 +52,10 @@ main (int argc, char **argv)
for
(
auto
entry
:
reader
.
entries
())
printf
(
"%s %zd
\n
"
,
entry
.
filename
.
c_str
(),
entry
.
data
.
size
());
}
else
if
(
argc
==
5
&&
strcmp
(
argv
[
1
],
"pcr"
)
==
0
)
{
return
pcr
(
argv
[
2
],
argv
[
3
],
atof
(
argv
[
4
]));
}
else
if
(
argc
==
4
&&
strcmp
(
argv
[
1
],
"get"
)
==
0
)
{
TSReader
reader
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment