Skip to content

Commit

Permalink
Merge pull request #550 from ksooo/fix_rds_parser_matrix
Browse files Browse the repository at this point in the history
Fix AAC RDS parser.
  • Loading branch information
ksooo authored Oct 27, 2021
2 parents 2ae1770 + f7ff2c3 commit c4c4154
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pvr.hts/addon.xml.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon
id="pvr.hts"
version="19.0.0"
version="19.0.1"
name="Tvheadend HTSP Client"
provider-name="Adam Sutton, Sam Stenvall, Lars Op den Kamp, Kai Sommerfeld">
<requires>@ADDON_DEPENDS@</requires>
Expand Down
9 changes: 4 additions & 5 deletions pvr.hts/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
v19.0.1
- Fix AAC RDS parser

v19.0.0
- Translations updates from Weblate
- ko_kr
- Changed test builds to 'Kodi 19 Matrix'
- Increased version to 19.0.0
- With start of Kodi 20 Nexus, takes addon as major the same version number as Kodi.
This done to know easier to which Kodi the addon works.
- Version numbering scheme change.

v8.4.0
- Add support for RDS data contained in AAC streams.
Expand Down
76 changes: 44 additions & 32 deletions src/aac/elements/DSE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "../BitStream.h"

#include <cstring>
#include <exception>

using namespace aac;
Expand Down Expand Up @@ -43,42 +44,53 @@ uint8_t DSE::DecodeRDS(BitStream& stream, uint8_t*& rdsdata)
if (byteAlign)
stream.ByteAlign();

if (count > 2) // we need at least 0xFE + some-other-byte + 0xFF
static constexpr int BUFFER_SIZE = 65536;
static uint8_t buffer[BUFFER_SIZE];
static int bufferpos = 0;

uint8_t ret = 0;

if (count > BUFFER_SIZE)
{
const uint8_t firstElem = static_cast<uint8_t>(stream.ReadBits(8));
if (firstElem == 0xFE) // could be RDS data start
{
rdsdata = new uint8_t[count];
rdsdata[0] = firstElem;

try
{
for (int i = 1; i < count; ++i)
rdsdata[i] = static_cast<uint8_t>(stream.ReadBits(8));

if (rdsdata[count - 1] == 0xFF) // RDS data end
return count; // Note: caller has to delete the data array
}
catch (std::exception&)
{
// cleanup and rethrow
delete[] rdsdata;
rdsdata = nullptr;
throw;
}

// data start with 0xFE, but do not end with 0xFF, thus no RDS data
delete[] rdsdata;
rdsdata = nullptr;
}
else
// data package too large! turn over with next package.
stream.SkipBits(8 * count);
bufferpos = 0;
return ret;
}

if (bufferpos + count > BUFFER_SIZE)
{
// buffer overflow! turn over now.
bufferpos = 0;
}

try
{
// collect data
for (int i = 0; i < count; ++i)
{
stream.SkipBits(8 * (count - 1));
buffer[bufferpos + i] = static_cast<uint8_t>(stream.ReadBits(8));
}
bufferpos += count;
}
else
catch (std::exception&)
{
stream.SkipBits(8 * count);
// cleanup and rethrow
bufferpos = 0;
throw;
}
return 0;

if (bufferpos > 0 && buffer[bufferpos - 1] == 0xFF)
{
if (buffer[0] == 0xFE)
{
// data package is complete. deliver it.
rdsdata = new uint8_t[bufferpos]; // Note: caller has to delete the data array
std::memcpy(rdsdata, buffer, bufferpos);
ret = bufferpos;
}
bufferpos = 0;
}

return ret;
}

0 comments on commit c4c4154

Please sign in to comment.