Skip to content

Commit

Permalink
converted raw pointers to smart pointers in most places
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxamp committed Mar 6, 2018
1 parent 5b6012a commit 14eb898
Show file tree
Hide file tree
Showing 22 changed files with 156 additions and 143 deletions.
4 changes: 2 additions & 2 deletions src/block.cpp
Expand Up @@ -120,9 +120,9 @@ size_t block::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr block::addChild(node_ptr child) {
node* block::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

void block::report(size_t offset, uint8_t indent) const {
Expand Down
17 changes: 9 additions & 8 deletions src/clusterlist.cpp
Expand Up @@ -79,7 +79,7 @@ clusterlist::clusterlist(const VSAPI* api, VSNodeRef *node, int blocks_per_clust
}

clusterlist::~clusterlist() {
delete cached_cluster;
// delete cached_cluster;
}

size_t clusterlist::getSize() const {
Expand All @@ -102,9 +102,9 @@ size_t clusterlist::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr clusterlist::addChild(node_ptr child) {
node* clusterlist::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

void clusterlist::report(size_t offset, uint8_t indent) const {
Expand All @@ -128,7 +128,7 @@ int clusterlist::getNumClusters() const {

caching_cluster::~caching_cluster() {
if(cached_cluster_number >= 0) {
delete cached_cluster;
// delete cached_cluster;
}
}

Expand All @@ -139,9 +139,9 @@ caching_cluster::caching_cluster(const VSAPI* api, VSNodeRef* node, const int16_
{
}

node_ptr caching_cluster::addChild(node_ptr child) {
node* caching_cluster::addChild(node_ptr child) {
(void) child;
return node_ptr(this);
return this;
}

void caching_cluster::report(size_t offset, uint8_t indent) const {
Expand All @@ -153,7 +153,8 @@ void caching_cluster::report(size_t offset, uint8_t indent) const {
void caching_cluster::cache_cluster(const uint64_t cluster_number) {
// implement caching of the last cluster and block(s) used
if(cluster_number != cached_cluster_number) {
node_ptr cluster = Cluster()->addChild(ClusterTimecode(cluster_number * frame_duration * blocks_per_cluster));
node_ptr cluster = Cluster();
cluster->addChild(ClusterTimecode(cluster_number * frame_duration * blocks_per_cluster));

char error_message[128];

Expand Down Expand Up @@ -184,7 +185,7 @@ void caching_cluster::cache_cluster(const uint64_t cluster_number) {

if(cluster_lock.try_lock_for(std::chrono::seconds(60))) {
if (cached_cluster_number >= 0) {
delete cached_cluster;
// delete cached_cluster;
}

cached_cluster_number = (int) cluster_number;
Expand Down
46 changes: 25 additions & 21 deletions src/cues.cpp
Expand Up @@ -26,23 +26,23 @@ SOFTWARE.
#include "../vsmkv/cues.h"
#include "../vsmkv/elements.h"

cues::cues(const std::string name, const vint& id, const clusterlist* list) :
cues::cues(const std::string name, const vint& id, const clusterlist_ptr list) :
cues(name, id, list, 15) {}

cues::cues(const std::string name, const vint& id, const clusterlist* list, const int cue_every_nth_cluster) :
cues::cues(const std::string name, const vint& id, const clusterlist_ptr list, const int cue_every_nth_cluster) :
element(name, id), list(list), cue_every_nth_cluster(cue_every_nth_cluster) {
assert(list != NULL);
}

node_ptr cues::addChild(node_ptr child) {
node* cues::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

/*
* rebuild the cue list when the parent is changed (should only happen once)
*/
void cues::setParent(node_ptr parent) {
void cues::setParent(node* parent) {
node::setParent(parent);

assert(children.size() == 0); // parent should not change
Expand All @@ -54,15 +54,17 @@ void cues::setParent(node_ptr parent) {
const int num_cues = (num_clusters - (num_clusters % cue_every_nth_cluster)) / cue_every_nth_cluster;

// calculate size of cues from dummy cue
node_ptr dummy_cue = CuePoint()
->addChild(CueTime(0, 4))
->addChild(CueTrackPositions()
->addChild(CueTrack())
->addChild(CueClusterPosition(0, 8))
)
auto track_positions = CueTrackPositions();
track_positions->addChild(CueTrack())
->addChild(CueClusterPosition(0, 8))
;

auto dummy_cue = CuePoint();
dummy_cue->addChild(CueTime(0, 4))
->addChild(track_positions)
;
const uint64_t cue_size = dummy_cue->getSize();
delete dummy_cue;
// delete dummy_cue;

// get position of cues element relative to segment
const uint64_t cue_offset = parent->getOffset(this);
Expand All @@ -72,19 +74,21 @@ void cues::setParent(node_ptr parent) {

if(children.size() > 0) {
// should never execute
for(node_ptr c : children) {
delete c;
}
// for(node_ptr c : children) {
// delete c;
// }
children.clear();
}

for(int i=0; i<num_cues; i++) {
node_ptr cue = CuePoint()
->addChild(CueTime(i * cluster_duration * cue_every_nth_cluster, 4))
->addChild(CueTrackPositions()
->addChild(CueTrack())
->addChild(CueClusterPosition(cluster_offset + i * cluster_size * cue_every_nth_cluster, 8))
)
auto track_positions = CueTrackPositions();
track_positions->addChild(CueTrack())
->addChild(CueClusterPosition(cluster_offset + i * cluster_size * cue_every_nth_cluster, 8))
;

auto cue = CuePoint();
cue->addChild(CueTime(i * cluster_duration * cue_every_nth_cluster, 4))
->addChild(track_positions)
;
assert(cue->getSize() == cue_size); // cue and dummy cue are not in sync! (forgot to add children?)
element::addChild(cue);
Expand Down
4 changes: 2 additions & 2 deletions src/element.cpp
Expand Up @@ -59,11 +59,11 @@ size_t element::output(char *buffer, size_t _size, size_t offset) const {

return written;
}
node_ptr element::addChild(node_ptr child) {
node* element::addChild(node_ptr child) {
node::addChild(child);
length += child->getSize();

return (node_ptr)(this);
return this;
}

void element::report(size_t offset, uint8_t indent) const {
Expand Down
4 changes: 2 additions & 2 deletions src/floating.cpp
Expand Up @@ -50,9 +50,9 @@ size_t floating::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr floating::addChild(node_ptr child) {
node* floating::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

void floating::report(size_t offset, uint8_t indent) const {
Expand Down
4 changes: 2 additions & 2 deletions src/integer.cpp
Expand Up @@ -50,9 +50,9 @@ size_t integer::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr integer::addChild(node_ptr child) {
node* integer::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

void integer::updateSize(void) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -268,7 +268,7 @@ int main(int argc, char **argv) {
fuse_opt_free_args(&f_args);

// cleanup internal structures
for(stream* s : options.streams) {
for(auto& s : options.streams) {
delete s;
}

Expand Down
22 changes: 9 additions & 13 deletions src/node.cpp
Expand Up @@ -26,14 +26,6 @@ SOFTWARE.
#include "../vsmkv/node.h"
#include "../vsmkv/utils.h"

node::~node() {
for(node_ptr child : children) {
delete child;
}

children.clear();
}

size_t node::getSize() const {
size_t ret = 0;

Expand Down Expand Up @@ -73,11 +65,11 @@ size_t node::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr node::addChild(node_ptr child) {
node* node::addChild(node_ptr child) {
children.push_back(child);
child->setParent(this);

return (node_ptr)(this);
return this;
}

void node::report(size_t offset, uint8_t indent) const {
Expand Down Expand Up @@ -106,12 +98,16 @@ void node::print_indent(uint8_t indent) const {
}
}

size_t node::getOffset(node_ptr child) {
size_t node::getOffset(const node_ptr& child) const {
return getOffset(child.get());
}

size_t node::getOffset(const node* child) const {
size_t ret = 0;
node_ptr c;
node* c;

uint64_t i;
for(i=0; i<children.size() && (c=children[i]) != child; i++) {
for(i=0; i<children.size() && (c=children[i].get()) != child; i++) {
ret += c->getSize();
}

Expand Down
113 changes: 62 additions & 51 deletions src/stream.cpp
Expand Up @@ -31,9 +31,9 @@ SOFTWARE.
#include "vsmkv/fourcc.h"
#include "vsmkv/cues.h"

stream::stream(const VSAPI* api, VSNodeRef *node, const int index) : api(api), node(node)
stream::stream(const VSAPI* api, VSNodeRef *_node, const int index) : api(api), node(_node)
{
const VSVideoInfo* vi = api->getVideoInfo(node);
const VSVideoInfo* vi = api->getVideoInfo(_node);

double _f = ((double) vi->fpsNum)/vi->fpsDen;
float fps = (float)_f;
Expand All @@ -51,55 +51,66 @@ stream::stream(const VSAPI* api, VSNodeRef *node, const int index) : api(api), n
// std::cout << "double fps: " << _f << " from " << vi->fpsNum << "/" << vi->fpsDen << " resulting in " << fps << " as float." << std::endl;
// std::cout << "frame format: " << vi->format->name << " with " << vi->format->bitsPerSample << " bits/sample and " << vi->format->numPlanes << " planes" << std::endl;

node_ptr cl = ClusterList(api, node);
node_ptr cues = Cues(static_cast<clusterlist*>(cl));

master = MasterNode()
->addChild(EBMLHead()
->addChild(EBMLVersion())
->addChild(EBMLReadVersion())
->addChild(EBMLMaxIDLength())
->addChild(EBMLMaxSizeLength())
->addChild(DocType("matroska"))
->addChild(DocTypeVersion())
->addChild(DocTypeReadVersion())
)
->addChild(Segment()
->addChild(Info()
->addChild(TimecodeScale())
->addChild(MuxingApp())
->addChild(WritingApp())
)
->addChild(Tracks()
->addChild(TrackEntry()
->addChild(TrackNumber(1))
->addChild(TrackUID(1))
->addChild(TrackType(video))
/* ->addChild(TrackFlagEnabled())
->addChild(TrackFlagDefault())
->addChild(TrackFlagForced())
->addChild(TrackFlagLacing()) */
->addChild(TrackMinCache())
/* ->addChild(MaxBlockAdditionID()) */
->addChild(CodecID())
->addChild(TrackDefaultDuration(duration))
->addChild(TrackVideo()
->addChild(VideoFPS(fps))
->addChild(VideoPixelWidth((uint64_t)vi->width))
->addChild(VideoPixelHeight((uint64_t)vi->height))
->addChild(VideoDisplayWidth((uint64_t)vi->width))
->addChild(VideoDisplayHeight((uint64_t)vi->height))
// ->addChild(VideoColorSpace(0x49343230)) // I420
->addChild(VideoColorSpace(cc_code))
// ->addChild(VideoColor()
// ->addChild(ColorBitsPerChannel(vi->format->bitsPerSample))
// )
)
)
)
->addChild(cues)
->addChild(cl)
)
auto cl = ClusterList(api, _node);
auto cues = Cues(cl);

auto head = EBMLHead();
head->addChild(EBMLVersion())
->addChild(EBMLReadVersion())
->addChild(EBMLMaxIDLength())
->addChild(EBMLMaxSizeLength())
->addChild(DocType("matroska"))
->addChild(DocTypeVersion())
->addChild(DocTypeReadVersion())
;

auto info = Info();
info->addChild(TimecodeScale())
->addChild(MuxingApp())
->addChild(WritingApp())
;

auto tv = TrackVideo();
tv->addChild(VideoFPS(fps))
->addChild(VideoPixelWidth((uint64_t)vi->width))
->addChild(VideoPixelHeight((uint64_t)vi->height))
->addChild(VideoDisplayWidth((uint64_t)vi->width))
->addChild(VideoDisplayHeight((uint64_t)vi->height))
// ->addChild(VideoColorSpace(0x49343230)) // I420
->addChild(VideoColorSpace(cc_code))
// ->addChild(VideoColor()
// ->addChild(ColorBitsPerChannel(vi->format->bitsPerSample))
// )
;

auto track_entry = TrackEntry();
track_entry->addChild(TrackNumber(1))
->addChild(TrackUID(1))
->addChild(TrackType(video))
/* ->addChild(TrackFlagEnabled())
->addChild(TrackFlagDefault())
->addChild(TrackFlagForced())
->addChild(TrackFlagLacing()) */
->addChild(TrackMinCache())
/* ->addChild(MaxBlockAdditionID()) */
->addChild(CodecID())
->addChild(TrackDefaultDuration(duration))
->addChild(tv)
;

auto tracks = Tracks();
tracks->addChild(track_entry);

auto segment = Segment();
segment->addChild(info)
->addChild(tracks)
->addChild(cues)
->addChild(cl)
;

master = MasterNode();
master->addChild(head)
->addChild(segment)
;

// TODO: debug
Expand Down
4 changes: 2 additions & 2 deletions src/string.cpp
Expand Up @@ -49,9 +49,9 @@ size_t string::output(char *buffer, size_t _size, size_t offset) const {
return written;
}

node_ptr string::addChild(node_ptr child) {
node* string::addChild(node_ptr child) {
(void) child;
return (node_ptr)(this);
return this;
}

void string::report(size_t offset, uint8_t indent) const {
Expand Down

0 comments on commit 14eb898

Please sign in to comment.