v3c: Add example for parsing and sending V3C files
This commit is contained in:
parent
b5905bcae2
commit
a3598cd6c4
|
@ -99,6 +99,7 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||
src/wrapper_c.cc
|
||||
src/socketfactory.cc
|
||||
src/rtcp_reader.cc
|
||||
src/v3c_parser.cc
|
||||
)
|
||||
|
||||
source_group(src/srtp src/srtp/.*)
|
||||
|
@ -152,6 +153,7 @@ target_sources(${PROJECT_NAME} PRIVATE
|
|||
src/srtp/srtcp.hh
|
||||
src/socketfactory.hh
|
||||
src/rtcp_reader.hh
|
||||
include/uvgrtp/v3c_parser.hh
|
||||
|
||||
include/uvgrtp/util.hh
|
||||
include/uvgrtp/clock.hh
|
||||
|
|
|
@ -13,6 +13,8 @@ add_executable(srtp_zrtp) # SRTP + ZRTP example
|
|||
add_executable(zrtp_multistream) # ZRTP Multistream example
|
||||
add_executable(sync_sender) # Syncing streams example, sender
|
||||
add_executable(sync_receiver) # Syncing streams example, receiver
|
||||
add_executable(v3c_receiver)
|
||||
add_executable(v3c_sender)
|
||||
|
||||
# Sources
|
||||
target_sources(binding PRIVATE binding.cc)
|
||||
|
@ -28,6 +30,8 @@ target_sources(srtp_zrtp PRIVATE srtp_zrtp.cc)
|
|||
target_sources(zrtp_multistream PRIVATE zrtp_multistream.cc)
|
||||
target_sources(sync_sender PRIVATE sync_sender.cc)
|
||||
target_sources(sync_receiver PRIVATE sync_receiver.cc)
|
||||
target_sources(v3c_receiver PRIVATE v3c_receiver.cc)
|
||||
target_sources(v3c_sender PRIVATE v3c_sender.cc)
|
||||
|
||||
# set crypto++ to be linked in examples if available
|
||||
if (NOT UVGRTP_DISABLE_CRYPTO AND CRYPTOPP_FOUND)
|
||||
|
@ -52,4 +56,6 @@ target_link_libraries(srtp_user PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
|||
target_link_libraries(srtp_zrtp PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(zrtp_multistream PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(sync_sender PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(sync_receiver PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(sync_receiver PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(v3c_receiver PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
||||
target_link_libraries(v3c_sender PRIVATE uvgrtp ${CRYPTOPP_LIB_NAME})
|
|
@ -0,0 +1,121 @@
|
|||
|
||||
#include <uvgrtp/lib.hh>
|
||||
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
/* There are two main ways of getting received RTP frames from uvgRTP.
|
||||
* This example demonstrates the usage of hook function to receive RTP frames.
|
||||
*
|
||||
* The advantage of using a hook function is minimal CPU usage and delay between
|
||||
* uvgRTP receiving the frame and application processing the frame. When using
|
||||
* the hook method, the application must take care that it is not using the hook
|
||||
* function for heavy processing since this may block RTP frame reception.
|
||||
*
|
||||
* Hook based frame reception is generally recommended for most serious applications,
|
||||
* but there can be situations where polling method is better, especially if performance
|
||||
* is not a huge concern or if there needs to be tight control when the frame is
|
||||
* received by the application.
|
||||
*
|
||||
* This example only implements the receiving, but it can be used together with the
|
||||
* sending example to test the functionality.
|
||||
*/
|
||||
|
||||
// parameters for this test. You can change these to suit your network environment
|
||||
constexpr uint16_t LOCAL_PORT = 8890;
|
||||
|
||||
constexpr char LOCAL_ADDRESS[] = "127.0.0.1";
|
||||
|
||||
// This example runs for 5 seconds
|
||||
constexpr auto RECEIVE_TIME_S = std::chrono::seconds(10);
|
||||
|
||||
void v3c_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame);
|
||||
void avc_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame);
|
||||
void cleanup(uvgrtp::context& ctx, uvgrtp::session* sess, uvgrtp::media_stream* receiver);
|
||||
uint64_t vbytes_received;
|
||||
uint64_t abytes_received;
|
||||
|
||||
int main(void)
|
||||
{
|
||||
std::cout << "Starting uvgRTP RTP receive hook example" << std::endl;
|
||||
|
||||
uvgrtp::context ctx;
|
||||
uvgrtp::session* sess = ctx.create_session(LOCAL_ADDRESS, LOCAL_ADDRESS);
|
||||
int flags = RCE_RECEIVE_ONLY;
|
||||
uvgrtp::media_stream* v3c = sess->create_stream(7790, 8890, RTP_FORMAT_V3C, flags);
|
||||
uvgrtp::media_stream* avc = sess->create_stream(7792, 8892, RTP_FORMAT_H265, flags);
|
||||
vbytes_received = 0;
|
||||
abytes_received = 0;
|
||||
/* Receive hook can be installed and uvgRTP will call this hook when an RTP frame is received
|
||||
*
|
||||
* This is a non-blocking operation
|
||||
*
|
||||
* If necessary, receive hook can be given an argument and this argument is supplied to
|
||||
* the receive hook every time the hook is called. This argument could a pointer to application-
|
||||
* specfic object if the application needs to be called inside the hook
|
||||
*
|
||||
* If it's not needed, it should be set to nullptr */
|
||||
if (!v3c || v3c->install_receive_hook(nullptr, v3c_receive_hook) != RTP_OK)
|
||||
{
|
||||
std::cerr << "Failed to install RTP reception hook";
|
||||
cleanup(ctx, sess, v3c);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if (!avc || avc->install_receive_hook(nullptr, avc_receive_hook) != RTP_OK)
|
||||
{
|
||||
std::cerr << "Failed to install RTP reception hook";
|
||||
cleanup(ctx, sess, avc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
std::cout << "Waiting incoming packets for " << RECEIVE_TIME_S.count() << " s" << std::endl;
|
||||
|
||||
std::this_thread::sleep_for(RECEIVE_TIME_S); // lets this example run for some time
|
||||
std::cout << "V3C Total bytes received " << vbytes_received << std::endl;
|
||||
std::cout << "AVC Total bytes received " << abytes_received << std::endl;
|
||||
|
||||
cleanup(ctx, sess, v3c);
|
||||
cleanup(ctx, sess, avc);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void v3c_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame)
|
||||
{
|
||||
std::cout << "Received V3C frame, size: " << frame->payload_len << " bytes" << std::endl;
|
||||
vbytes_received += frame->payload_len;
|
||||
/* Now we own the frame. Here you could give the frame to the application
|
||||
* if f.ex "arg" was some application-specific pointer
|
||||
*
|
||||
* arg->copy_frame(frame) or whatever
|
||||
*
|
||||
* When we're done with the frame, it must be deallocated manually */
|
||||
(void)uvgrtp::frame::dealloc_frame(frame);
|
||||
}
|
||||
void avc_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame)
|
||||
{
|
||||
std::cout << "Received AVC frame, size: " << frame->payload_len << " bytes" << std::endl;
|
||||
abytes_received += frame->payload_len;
|
||||
/* Now we own the frame. Here you could give the frame to the application
|
||||
* if f.ex "arg" was some application-specific pointer
|
||||
*
|
||||
* arg->copy_frame(frame) or whatever
|
||||
*
|
||||
* When we're done with the frame, it must be deallocated manually */
|
||||
(void)uvgrtp::frame::dealloc_frame(frame);
|
||||
}
|
||||
|
||||
void cleanup(uvgrtp::context& ctx, uvgrtp::session* sess, uvgrtp::media_stream* receiver)
|
||||
{
|
||||
if (receiver)
|
||||
{
|
||||
sess->destroy_stream(receiver);
|
||||
}
|
||||
|
||||
if (sess)
|
||||
{
|
||||
/* Session must be destroyed manually */
|
||||
ctx.destroy_session(sess);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,107 @@
|
|||
#include <uvgrtp/lib.hh>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
constexpr char REMOTE_ADDRESS[] = "127.0.0.1";
|
||||
constexpr uint16_t REMOTE_PORT = 8890;
|
||||
|
||||
// the parameters of demostration
|
||||
constexpr size_t PAYLOAD_LEN = 100;
|
||||
constexpr int AMOUNT_OF_TEST_PACKETS = 100;
|
||||
constexpr auto END_WAIT = std::chrono::seconds(5);
|
||||
|
||||
//std::string PATH = "C:\\Users\\ngheta\\Documents\\TMIV_A3_C_QP3.bit";
|
||||
std::string PATH = "C:\\Users\\ngheta\\Documents\\test_seq3.vpcc";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
std::cout << "Parsing V3C file" << std::endl;
|
||||
|
||||
/* A V3C Sample stream is divided into 6 types of 'sub-bitstreams' + parameters.
|
||||
- The ad_map vector holds the locations and sizes of Atlas NAL units in the file (both AD and CAD)
|
||||
- The vd_map holds the locations and sizes of all video V3C units (OVD, GVD, AVD, PVD)
|
||||
- First uint64_t is the start position of the unit, second is the size
|
||||
- With this info you can send the data via different uvgRTP media streams */
|
||||
|
||||
std::vector<std::pair<uint64_t, uint64_t>> ad_map = {};
|
||||
std::vector<std::pair<uint64_t, uint64_t>> vd_map = {};
|
||||
|
||||
uint64_t len = get_size(PATH);
|
||||
uint64_t ptr = 0;
|
||||
char* cbuf = nullptr;
|
||||
cbuf = get_cmem(PATH, len);
|
||||
|
||||
vuh_vps parameters = {};
|
||||
mmap_v3c_file(cbuf, len, parameters, ad_map, vd_map);
|
||||
|
||||
std::cout << "Sending Atlas NAL units via uvgRTP" << std::endl;
|
||||
|
||||
uvgrtp::context ctx;
|
||||
uvgrtp::session* sess = ctx.create_session(REMOTE_ADDRESS, REMOTE_ADDRESS);
|
||||
int flags = RCE_SEND_ONLY;
|
||||
uvgrtp::media_stream* v3c = sess->create_stream(8890, 7790, RTP_FORMAT_V3C, flags);
|
||||
uvgrtp::media_stream* vid = nullptr;
|
||||
|
||||
// Create the uvgRTP media stream with the correct RTP format
|
||||
if (parameters.ptl.ptl_profile_codec_group_idc == CODEC_AVC) {
|
||||
std::cout << "Video codec: AVC Progressive High" << std::endl;
|
||||
vid = sess->create_stream(8892, 7792, RTP_FORMAT_H264, flags);
|
||||
}
|
||||
else if (parameters.ptl.ptl_profile_codec_group_idc == CODEC_HEVC_MAIN10) {
|
||||
std::cout << "Video codec: HEVC Main10" << std::endl;
|
||||
vid = sess->create_stream(8892, 7792, RTP_FORMAT_H265, flags);
|
||||
}
|
||||
else if (parameters.ptl.ptl_profile_codec_group_idc == CODEC_HEVC444) {
|
||||
std::cout << "Video codec: HEVC444" << std::endl;
|
||||
vid = sess->create_stream(8892, 7792, RTP_FORMAT_H265, flags);
|
||||
}
|
||||
else if (parameters.ptl.ptl_profile_codec_group_idc == CODEC_VVC_MAIN10) {
|
||||
std::cout << "Video codec: VVC Main10" << std::endl;
|
||||
vid = sess->create_stream(8892, 7792, RTP_FORMAT_H266, flags);
|
||||
}
|
||||
|
||||
|
||||
uint64_t v3c_bytes_sent = 0;
|
||||
uint64_t avc_bytes_sent = 0;
|
||||
uint64_t send_ptr = 0;
|
||||
for (auto p : ad_map)
|
||||
{
|
||||
std::cout << "Sending frame in location " << p.first << " with size " << p.second << std::endl;
|
||||
|
||||
if (v3c->push_frame((uint8_t*)cbuf + p.first, p.second, RTP_NO_FLAGS) != RTP_OK)
|
||||
{
|
||||
std::cout << "Failed to send RTP frame!" << std::endl;
|
||||
}
|
||||
else {
|
||||
v3c_bytes_sent += p.second;
|
||||
}
|
||||
}
|
||||
for (auto p : vd_map)
|
||||
{
|
||||
std::cout << "Sending frame in location " << p.first << " with size " << p.second << std::endl;
|
||||
|
||||
if (vid->push_frame((uint8_t*)cbuf + p.first, p.second, RTP_NO_FLAGS) != RTP_OK)
|
||||
{
|
||||
std::cout << "Failed to send RTP frame!" << std::endl;
|
||||
}
|
||||
else {
|
||||
avc_bytes_sent += p.second;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "V3C Sending finished. Total bytes sent " << v3c_bytes_sent << std::endl;
|
||||
std::cout << "AVC Sending finished. Total bytes sent " << avc_bytes_sent << std::endl;
|
||||
|
||||
sess->destroy_stream(v3c);
|
||||
sess->destroy_stream(vid);
|
||||
if (sess)
|
||||
{
|
||||
// Session must be destroyed manually
|
||||
ctx.destroy_session(sess);
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
|
@ -13,3 +13,4 @@
|
|||
#include "frame.hh" // frame related functions
|
||||
#include "util.hh" // types
|
||||
#include "version.hh" // version
|
||||
#include "v3c_parser.hh" // v3c parser
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
// vuh_unit_type definitions:
|
||||
constexpr int V3C_VPS = 0; // V3C parameter set
|
||||
constexpr int V3C_AD = 1; // Atlas data
|
||||
constexpr int V3C_OVD = 2; // Occupancy video data
|
||||
constexpr int V3C_GVD = 3; // Geometry video data
|
||||
constexpr int V3C_AVD = 4; // Attribute video data
|
||||
constexpr int V3C_PVD = 5; // Packed video data
|
||||
constexpr int V3C_CAD = 6; // Common atlas data
|
||||
|
||||
constexpr int CODEC_AVC = 0; // AVC Progressive High
|
||||
constexpr int CODEC_HEVC_MAIN10 = 1; // HEVC Main10
|
||||
constexpr int CODEC_HEVC444 = 2; // HEVC444
|
||||
constexpr int CODEC_VVC_MAIN10 = 3; // VVC Main10
|
||||
|
||||
constexpr int V3C_HDR_LEN = 4; // 32 bits for v3c unit header
|
||||
|
||||
constexpr uint8_t VVC_SC = 0x00000001; // VVC Start Code
|
||||
|
||||
struct profile_tier_level {
|
||||
uint8_t ptl_tier_flag = 0;
|
||||
uint8_t ptl_profile_codec_group_idc = 0;
|
||||
};
|
||||
struct vuh_vps {
|
||||
profile_tier_level ptl;
|
||||
};
|
||||
struct vuh_ad {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
};
|
||||
struct vuh_ovd {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
};
|
||||
struct vuh_gvd {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
uint8_t vuh_map_index = 0;
|
||||
bool vuh_auxiliary_video_flag = 0;
|
||||
};
|
||||
struct vuh_avd {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
uint8_t vuh_attribute_index = 0;
|
||||
uint8_t vuh_attribute_partition_index = 0;
|
||||
uint8_t vuh_map_index = 0;
|
||||
bool vuh_auxiliary_video_flag = 0;
|
||||
};
|
||||
struct vuh_pvd {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
};
|
||||
struct vuh_cad {
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;
|
||||
};
|
||||
|
||||
struct v3c_unit_header {
|
||||
uint8_t vuh_unit_type = 0;
|
||||
union {
|
||||
vuh_vps vps;
|
||||
vuh_ad ad;
|
||||
vuh_ovd ovd;
|
||||
vuh_gvd gvd;
|
||||
vuh_avd avd;
|
||||
vuh_pvd pvd;
|
||||
vuh_cad cad;
|
||||
};
|
||||
};
|
||||
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2, uint8_t byte3);
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2);
|
||||
|
||||
uint64_t get_size(std::string filename);
|
||||
char* get_cmem(std::string filename, const size_t& len);
|
||||
|
||||
// ad is for AD and CAD substreams, vd is for all VD substreams
|
||||
bool mmap_v3c_file(char* cbuf, uint64_t len, vuh_vps& param, std::vector<std::pair<uint64_t, uint64_t>>& ad,
|
||||
std::vector<std::pair<uint64_t, uint64_t>>& vd);
|
||||
void parse_v3c_header(v3c_unit_header &hdr, char* buf, uint64_t ptr);
|
|
@ -0,0 +1,253 @@
|
|||
#include "uvgrtp/v3c_parser.hh"
|
||||
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4) {
|
||||
return (static_cast<uint32_t>(byte1) << 24) |
|
||||
(static_cast<uint32_t>(byte2) << 16) |
|
||||
(static_cast<uint32_t>(byte3) << 8) |
|
||||
static_cast<uint32_t>(byte4);
|
||||
}
|
||||
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2, uint8_t byte3) {
|
||||
return (static_cast<uint32_t>(byte1) << 16) |
|
||||
(static_cast<uint32_t>(byte2) << 8) |
|
||||
static_cast<uint32_t>(byte3);
|
||||
}
|
||||
|
||||
uint32_t combineBytes(uint8_t byte1, uint8_t byte2) {
|
||||
return (static_cast<uint32_t>(byte1) << 8) |
|
||||
(static_cast<uint32_t>(byte2));
|
||||
}
|
||||
|
||||
bool mmap_v3c_file(char* cbuf, uint64_t len, vuh_vps& param, std::vector<std::pair<uint64_t, uint64_t>>& ad,
|
||||
std::vector<std::pair<uint64_t, uint64_t>>& vd)
|
||||
{
|
||||
uint64_t ptr = 0;
|
||||
|
||||
// First byte is the file header
|
||||
uint8_t first_byte = cbuf[ptr];
|
||||
std::cout << "First byte " << uint32_t(first_byte) << std::endl;
|
||||
uint8_t v3c_size_precision = (first_byte >> 5) + 1;
|
||||
std::cout << "V3C size precision: " << (uint32_t)v3c_size_precision << std::endl;
|
||||
std::cout << std::endl;
|
||||
++ptr;
|
||||
|
||||
uint8_t* v3c_size = new uint8_t[v3c_size_precision];
|
||||
|
||||
std::vector<uint32_t> sizes = {};
|
||||
while (true) {
|
||||
if (ptr >= len) {
|
||||
break;
|
||||
}
|
||||
// Readthe V3C unit size (2-3 bytes usually)
|
||||
memcpy(v3c_size, &cbuf[ptr], v3c_size_precision);
|
||||
ptr += v3c_size_precision; // Jump over the V3C unit size bytes
|
||||
uint32_t combined_v3c_size = 0;
|
||||
if (v3c_size_precision == 2) {
|
||||
combined_v3c_size = combineBytes(v3c_size[0], v3c_size[1]);
|
||||
}
|
||||
else if (v3c_size_precision == 3) {
|
||||
combined_v3c_size = combineBytes(v3c_size[0], v3c_size[1], v3c_size[2]);
|
||||
}
|
||||
else {
|
||||
std::cout << "Error " << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
// Inside v3c unit now
|
||||
std::cout << "Current V3C unit size " << combined_v3c_size << std::endl;
|
||||
uint64_t v3c_ptr = ptr;
|
||||
|
||||
// Next 4 bytes are the V3C unit header
|
||||
v3c_unit_header v3c_hdr = {};
|
||||
parse_v3c_header(v3c_hdr, cbuf, v3c_ptr);
|
||||
uint8_t vuh_t = v3c_hdr.vuh_unit_type;
|
||||
std::cout << "-- vuh_unit_type: " << (uint32_t)vuh_t << std::endl;
|
||||
|
||||
if (vuh_t == V3C_VPS) {
|
||||
// Parameter set contains no NAL units, skip over
|
||||
std::cout << "-- Parameter set V3C unit" << std::endl;
|
||||
ptr += combined_v3c_size;
|
||||
sizes.push_back(combined_v3c_size);
|
||||
param = v3c_hdr.vps;
|
||||
std::cout << std::endl;
|
||||
continue;
|
||||
}
|
||||
else if (vuh_t == V3C_OVD || vuh_t == V3C_GVD || vuh_t == V3C_AVD || vuh_t == V3C_PVD) {
|
||||
// Video data, map start and size
|
||||
std::cout << "-- Video data V3C unit, " << std::endl;
|
||||
vd.push_back({ ptr + V3C_HDR_LEN, combined_v3c_size });
|
||||
ptr += combined_v3c_size;
|
||||
std::cout << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Rest of the function goes inside the V3C unit payload and parses NAL it into NAL units
|
||||
v3c_ptr += V3C_HDR_LEN; // Jump over 4 bytes of V3C unit header
|
||||
|
||||
uint8_t v3cu_first_byte = cbuf[v3c_ptr]; // Next up is 1 byte of NAL unit size precision
|
||||
uint8_t nal_size_precision = (v3cu_first_byte >> 5) + 1;
|
||||
std::cout << " -- NAL Sample stream, 1 byte for NAL unit size precision: " << (uint32_t)nal_size_precision << std::endl;
|
||||
++v3c_ptr;
|
||||
|
||||
// Now start to parse the NAL sample stream
|
||||
while (true) {
|
||||
if (v3c_ptr >= (ptr + combined_v3c_size)) {
|
||||
break;
|
||||
}
|
||||
uint32_t combined_nal_size = 0;
|
||||
if (nal_size_precision == 2) {
|
||||
combined_nal_size = combineBytes(cbuf[v3c_ptr], cbuf[v3c_ptr + 1]);
|
||||
}
|
||||
else if (nal_size_precision == 3) {
|
||||
combined_nal_size = combineBytes(cbuf[v3c_ptr], cbuf[v3c_ptr + 1], cbuf[v3c_ptr + 2]);
|
||||
}
|
||||
else {
|
||||
std::cout << " -- Error, invalid NAL size " << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
v3c_ptr += nal_size_precision;
|
||||
std::cout << " -- NALU size: " << combined_nal_size << std::endl;
|
||||
switch (vuh_t) {
|
||||
case V3C_AD:
|
||||
case V3C_CAD:
|
||||
ad.push_back({ v3c_ptr, combined_nal_size });
|
||||
break;
|
||||
|
||||
}
|
||||
v3c_ptr += combined_nal_size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::cout << std::endl;
|
||||
ptr += combined_v3c_size;
|
||||
sizes.push_back(combined_v3c_size);
|
||||
}
|
||||
std::cout << "File parsed" << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
void parse_v3c_header(v3c_unit_header &hdr, char* buf, uint64_t ptr)
|
||||
{
|
||||
uint8_t vuh_unit_type = (buf[ptr] & 0b11111000) >> 3;
|
||||
hdr.vuh_unit_type = vuh_unit_type;
|
||||
|
||||
uint8_t vuh_v3c_parameter_set_id = 0;;
|
||||
uint8_t vuh_atlas_id = 0;
|
||||
|
||||
if (vuh_unit_type == V3C_AVD || vuh_unit_type == V3C_GVD ||
|
||||
vuh_unit_type == V3C_OVD || vuh_unit_type == V3C_AD ||
|
||||
vuh_unit_type == V3C_CAD || vuh_unit_type == V3C_PVD) {
|
||||
|
||||
// 3 last bits from first byte and 1 first bit from second byte
|
||||
vuh_v3c_parameter_set_id = ((buf[ptr] & 0b111) << 1) | ((buf[ptr + 1] & 0b10000000) >> 7);
|
||||
std::cout << "-- vuh_v3c_parameter_set_id: " << (uint32_t)vuh_v3c_parameter_set_id << std::endl;
|
||||
}
|
||||
if (vuh_unit_type == V3C_AVD || vuh_unit_type == V3C_GVD ||
|
||||
vuh_unit_type == V3C_OVD || vuh_unit_type == V3C_AD ||
|
||||
vuh_unit_type == V3C_PVD) {
|
||||
|
||||
// 6 middle bits from the second byte
|
||||
vuh_atlas_id = ((buf[ptr + 1] & 0b01111110) >> 1);
|
||||
std::cout << "-- vuh_atlas_id: " << (uint32_t)vuh_atlas_id << std::endl;
|
||||
}
|
||||
|
||||
switch (hdr.vuh_unit_type) {
|
||||
case V3C_VPS:
|
||||
hdr.vps = {};
|
||||
// first bit of first byte
|
||||
hdr.vps.ptl.ptl_tier_flag = buf[ptr + 4] >> 7;
|
||||
std::cout << "-- ptl_tier_flag: " << (uint32_t)hdr.vps.ptl.ptl_tier_flag << std::endl;
|
||||
// 7 bits after
|
||||
hdr.vps.ptl.ptl_profile_codec_group_idc = buf[ptr + 4] & 0b01111111;
|
||||
std::cout << "-- ptl_profile_codec_group_idc: " << (uint32_t)hdr.vps.ptl.ptl_profile_codec_group_idc << std::endl;
|
||||
break;
|
||||
|
||||
case V3C_AD:
|
||||
hdr.ad = {};
|
||||
hdr.ad.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
hdr.ad.vuh_atlas_id = vuh_atlas_id;
|
||||
break;
|
||||
|
||||
case V3C_OVD:
|
||||
hdr.ovd = {};
|
||||
hdr.ovd.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
hdr.ovd.vuh_atlas_id = vuh_atlas_id;
|
||||
break;
|
||||
|
||||
case V3C_GVD:
|
||||
hdr.gvd = {};
|
||||
hdr.gvd.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
hdr.gvd.vuh_atlas_id = vuh_atlas_id;
|
||||
// last bit of second byte and 3 first bytes of third byte
|
||||
hdr.gvd.vuh_map_index = ((buf[ptr + 1] & 0b1) << 3) | ((buf[ptr + 2] & 0b11100000) >> 5);
|
||||
std::cout << "-- vuh_map_index: " << (uint32_t)hdr.gvd.vuh_map_index << std::endl;
|
||||
// fourth bit of third byte
|
||||
hdr.gvd.vuh_auxiliary_video_flag = (buf[ptr + 2] & 0b00010000) >> 4;
|
||||
std::cout << "-- vuh_auxiliary_video_flag: " << (uint32_t)hdr.gvd.vuh_auxiliary_video_flag << std::endl;
|
||||
break;
|
||||
|
||||
case V3C_AVD:
|
||||
hdr.avd = {};
|
||||
hdr.avd.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
hdr.avd.vuh_atlas_id = vuh_atlas_id;
|
||||
// last bit of second byte and 6 first bytes of third byte
|
||||
hdr.avd.vuh_attribute_index = ((buf[ptr + 1] & 0b1) << 6) | ((buf[ptr + 2] & 0b11111100) >> 2);
|
||||
std::cout << "-- vuh_attribute_index: " << (uint32_t)hdr.avd.vuh_attribute_index << std::endl;
|
||||
// 2 last bits of third byte and 3 first b<>ts of fourth byte
|
||||
hdr.avd.vuh_attribute_partition_index = (buf[ptr + 2] & 0b11) | ((buf[ptr + 3] & 0b11100000) >> 5);
|
||||
std::cout << "-- vuh_attribute_partition_index: " << (uint32_t)hdr.avd.vuh_attribute_index << std::endl;
|
||||
// fourth byte: 4 bits
|
||||
hdr.avd.vuh_map_index = (buf[ptr + 3] & 0b00011110) >> 1;
|
||||
std::cout << "-- vuh_map_index: " << (uint32_t)hdr.avd.vuh_map_index << std::endl;
|
||||
// last bit of fourth byte
|
||||
hdr.avd.vuh_auxiliary_video_flag = (buf[ptr + 3] & 0b1);
|
||||
std::cout << "-- vuh_auxiliary_video_flag: " << (uint32_t)hdr.avd.vuh_auxiliary_video_flag << std::endl;
|
||||
break;
|
||||
|
||||
case V3C_PVD:
|
||||
hdr.pvd = {};
|
||||
hdr.pvd.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
hdr.pvd.vuh_atlas_id = vuh_atlas_id;
|
||||
break;
|
||||
|
||||
case V3C_CAD:
|
||||
hdr.cad = {};
|
||||
hdr.cad.vuh_v3c_parameter_set_id = vuh_v3c_parameter_set_id;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint64_t get_size(std::string filename)
|
||||
{
|
||||
std::ifstream infile(filename, std::ios_base::binary);
|
||||
|
||||
|
||||
//get length of file
|
||||
infile.seekg(0, infile.end);
|
||||
size_t length = infile.tellg();
|
||||
infile.seekg(0, infile.beg);
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
char* get_cmem(std::string filename, const size_t& len)
|
||||
{
|
||||
std::ifstream infile(filename, std::ios_base::binary);
|
||||
|
||||
char* buf = new char[len];
|
||||
// read into char*
|
||||
if (!(infile.read(buf, len))) // read up to the size of the buffer
|
||||
{
|
||||
if (!infile.eof())
|
||||
{
|
||||
std::cerr << "Failed to read file contents." << std::endl;
|
||||
delete[] buf; // Free memory before returning nullptr
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
Loading…
Reference in New Issue