Move opus_packet_tick_count() to main opus library code
This commit is contained in:
parent
1f8e008d6e
commit
f3dd0ddc7d
6 changed files with 30 additions and 31 deletions
|
@ -68,14 +68,4 @@ struct oggopus_tags parse_oggopus_tags(struct ogg::packet& packet) throw(std::ba
|
|||
uint32_t serialize_oggopus_tags(struct oggopus_tags& tags, std::function<void(const ogg::page& p)> output,
|
||||
uint32_t strmid) throw(std::bad_alloc, std::runtime_error);
|
||||
|
||||
/**
|
||||
* Get tick (2.5ms) count from opus packet.
|
||||
*
|
||||
* Parameter packet: The packet data.
|
||||
* Parameter packetsize: The size of packet.
|
||||
*
|
||||
* Note: Guaranteed not to read more than 2 bytes from the packet.
|
||||
*/
|
||||
uint8_t opus_packet_tick_count(const uint8_t* packet, size_t packetsize);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -639,5 +639,15 @@ uint32_t packet_get_nb_channels(const unsigned char* packet);
|
|||
bandwidth packet_get_bandwidth(const unsigned char* packet);
|
||||
parsed_packet packet_parse(const unsigned char* packet, size_t len);
|
||||
std::string version();
|
||||
|
||||
/**
|
||||
* Get tick (2.5ms) count from opus packet.
|
||||
*
|
||||
* Parameter packet: The packet data.
|
||||
* Parameter packetsize: The size of packet.
|
||||
*
|
||||
* Note: Guaranteed not to read more than 2 bytes from the packet.
|
||||
*/
|
||||
uint8_t packet_tick_count(const uint8_t* packet, size_t packetsize);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -481,7 +481,7 @@ out_parsing:
|
|||
case 2: //Data page.
|
||||
case 3: //Data page.
|
||||
const std::vector<uint8_t>& pkt = p.get_vector();
|
||||
uint8_t tcnt = opus_packet_tick_count(&pkt[0], pkt.size());
|
||||
uint8_t tcnt = opus::packet_tick_count(&pkt[0], pkt.size());
|
||||
if(tcnt) {
|
||||
write(tcnt, &pkt[0], pkt.size());
|
||||
datalen += tcnt * 120;
|
||||
|
@ -655,7 +655,7 @@ out:
|
|||
}
|
||||
if(!p.size())
|
||||
(stringfmt() << "Empty Opus packet is not valid").throwex();
|
||||
uint32_t samples = static_cast<uint32_t>(opus_packet_tick_count(&p[0], p.size())) * 120;
|
||||
uint32_t samples = static_cast<uint32_t>(opus::packet_tick_count(&p[0], p.size())) * 120;
|
||||
if(i + 1 < packets.size())
|
||||
true_granule += samples;
|
||||
else
|
||||
|
|
|
@ -450,7 +450,7 @@ namespace sky
|
|||
{
|
||||
std::pair<uint32_t, uint64_t> ptsx = std::make_pair(ctx.psid, ctx.pts);
|
||||
packetdata[ptsx] = p.get_vector();
|
||||
uint8_t t = opus_packet_tick_count(&packetdata[ptsx][0], packetdata[ptsx].size());
|
||||
uint8_t t = opus::packet_tick_count(&packetdata[ptsx][0], packetdata[ptsx].size());
|
||||
ctx.pts += 120 * t;
|
||||
if(p.get_last_page()) {
|
||||
uint64_t samples = p.get_granulepos() - ctx.last_granule;
|
||||
|
@ -513,7 +513,7 @@ namespace sky
|
|||
s = d->decode(&data[0], data.size(), dmem, 5760);
|
||||
else {
|
||||
//Insert silence.
|
||||
uint8_t ticks = opus_packet_tick_count(&data[0], data.size());
|
||||
uint8_t ticks = opus::packet_tick_count(&data[0], data.size());
|
||||
if(!ticks)
|
||||
ticks = 1; //Try to recover.
|
||||
memset(pcmbuf, 0, 240 * ticks * sizeof(int16_t));
|
||||
|
@ -524,7 +524,7 @@ namespace sky
|
|||
} catch(std::exception& e) {
|
||||
//Try to insert silence.
|
||||
messages << "Failed to decode opus packet: " << e.what() << std::endl;
|
||||
uint8_t ticks = opus_packet_tick_count(&data[0], data.size());
|
||||
uint8_t ticks = opus::packet_tick_count(&data[0], data.size());
|
||||
if(!ticks)
|
||||
ticks = 1; //Try to recover.
|
||||
memset(pcmbuf, 0, 240 * ticks * sizeof(int16_t));
|
||||
|
|
|
@ -168,19 +168,3 @@ uint32_t serialize_oggopus_tags(struct oggopus_tags& tags, std::function<void(co
|
|||
written = ptr - &contents[0];
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t opus_packet_tick_count(const uint8_t* packet, size_t packetsize)
|
||||
{
|
||||
if(packetsize < 1)
|
||||
return 0;
|
||||
uint8_t x = ((packet[0] >= 0x70) ? 1 : 4) << ((packet[0] >> 3) & 3);
|
||||
x = min(x, (uint8_t)24);
|
||||
uint8_t y = (packetsize < 2) ? 255 : (packet[1] & 0x3F);
|
||||
uint16_t z = (uint16_t)x * y;
|
||||
switch(packet[0] & 3) {
|
||||
case 0: return x;
|
||||
case 1: return x << 1;
|
||||
case 2: return x << 1;
|
||||
case 3: return (z <= 48) ? z : 0;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1669,4 +1669,19 @@ std::string version()
|
|||
return opus_get_version_string();
|
||||
}
|
||||
|
||||
uint8_t packet_tick_count(const uint8_t* packet, size_t packetsize)
|
||||
{
|
||||
if(packetsize < 1)
|
||||
return 0;
|
||||
uint8_t x = ((packet[0] >= 0x70) ? 1 : 4) << ((packet[0] >> 3) & 3);
|
||||
x = std::min(x, (uint8_t)24);
|
||||
uint8_t y = (packetsize < 2) ? 255 : (packet[1] & 0x3F);
|
||||
uint16_t z = (uint16_t)x * y;
|
||||
switch(packet[0] & 3) {
|
||||
case 0: return x;
|
||||
case 1: return x << 1;
|
||||
case 2: return x << 1;
|
||||
case 3: return (z <= 48) ? z : 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue