From cbed47ea5fbdf891aaccfd294ed282e7a5c9afa2 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Tue, 10 Sep 2013 12:59:06 -0500 Subject: [PATCH] Changed / Refactored many enums and structs, to better standardize the naming of everything. Improved some more descriptions and briefs. --- .project | 1 + .pydevproject | 7 +++++++ include/AudioBufferSource.h | 1 + include/AudioResampler.h | 7 ++++--- include/Cache.h | 7 +++---- include/ChunkReader.h | 11 ++++++++--- include/Coordinate.h | 1 - include/DummyReader.h | 7 ++++--- include/FFmpegReader.h | 17 ++++++++++------- include/FFmpegWriter.h | 4 ++-- include/FrameMapper.h | 6 +++--- include/KeyFrame.h | 2 +- include/OpenShot.h | 2 +- include/Point.h | 14 +++++++------- include/Timeline.h | 2 +- src/CMakeLists.txt | 2 +- src/FFmpegReader.cpp | 8 ++++---- src/FFmpegWriter.cpp | 2 +- src/FrameMapper.cpp | 2 +- src/KeyFrame.cpp | 2 +- src/Main.cpp | 8 ++++---- src/Point.cpp | 8 ++++---- src/Timeline.cpp | 2 +- src/examples/test.py | 33 --------------------------------- tests/CMakeLists.txt | 2 +- tests/Point_Tests.cpp | 6 +++--- 26 files changed, 74 insertions(+), 90 deletions(-) create mode 100644 .pydevproject delete mode 100644 src/examples/test.py diff --git a/.project b/.project index c2cd6a22..4b5848a1 100644 --- a/.project +++ b/.project @@ -83,5 +83,6 @@ org.eclipse.cdt.core.ccnature org.eclipse.cdt.managedbuilder.core.managedBuildNature org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + org.python.pydev.pythonNature diff --git a/.pydevproject b/.pydevproject new file mode 100644 index 00000000..f8c0075c --- /dev/null +++ b/.pydevproject @@ -0,0 +1,7 @@ + + + + +Default +python 2.6 + diff --git a/include/AudioBufferSource.h b/include/AudioBufferSource.h index 7c7ebef2..fa9a2759 100644 --- a/include/AudioBufferSource.h +++ b/include/AudioBufferSource.h @@ -41,6 +41,7 @@ using namespace std; +/// This namespace is the default namespace for all code in the openshot library namespace openshot { diff --git a/include/AudioResampler.h b/include/AudioResampler.h index 89498516..4c44a46b 100644 --- a/include/AudioResampler.h +++ b/include/AudioResampler.h @@ -42,12 +42,13 @@ #include "AudioBufferSource.h" #include "Exceptions.h" -/// This namespace is the default namespace for all code in the openshot library. namespace openshot { /** - * @brief This class is used to resample audio data for many sequential frames. It maintains some data from the last - * call to GetResampledBuffer(), so there are no pops and clicks between frames. + * @brief This class is used to resample audio data for many sequential frames. + * + * It maintains some data from the last call to GetResampledBuffer(), so there + * are no pops and clicks between frames. */ class AudioResampler { private: diff --git a/include/Cache.h b/include/Cache.h index b841e577..af6acca0 100644 --- a/include/Cache.h +++ b/include/Cache.h @@ -34,14 +34,13 @@ #include "Frame.h" #include "Exceptions.h" -/// This namespace is the default namespace for all code in the openshot library. namespace openshot { /** - * @brief This class is a cache manager for Frame objects. It is used by FileReaders (such as FFmpegReader) to cache - * recently accessed frames. + * @brief This class is a cache manager for Frame objects. * - * Due to the high cost of decoding streams, once a frame is decoded, converted to RGB, and a Frame object is created, + * It is used by FileReaders (such as FFmpegReader) to cache recently accessed frames. Due to the + * high cost of decoding streams, once a frame is decoded, converted to RGB, and a Frame object is created, * it critical to keep these Frames cached for performance reasons. However, the larger the cache, the more memory * is required. You can set the max number of bytes to cache. */ diff --git a/include/ChunkReader.h b/include/ChunkReader.h index 1783cb92..570991c0 100644 --- a/include/ChunkReader.h +++ b/include/ChunkReader.h @@ -64,8 +64,8 @@ namespace openshot }; /** - * @brief This version enumeration allows the user to choose which version - * of the chunk they would like (low quality, medium, or high quality). + * @brief This enumeration allows the user to choose which version + * of the chunk they would like (low, medium, or high quality). * * Since chunks contain multiple video streams, this version enumeration * allows the user to choose which version of the chunk they would like. @@ -82,7 +82,12 @@ namespace openshot /** * @brief This class reads a special chunk-formatted file, which can be easily - * shared in a distributed environment, and can return openshot::Frame objects. + * shared in a distributed environment. + * + * It stores the video in small "chunks", which are really just short video clips, + * a few seconds each. A ChunkReader only needs the part of the chunk that contains + * the frames it is looking for. For example, if you only need the end of a video, + * only the last few chunks might be needed to successfully access those openshot::Frame objects. * * \code * // This example demonstrates how to read a chunk folder and access frame objects inside it. diff --git a/include/Coordinate.h b/include/Coordinate.h index 41f8cc0a..0772ea28 100644 --- a/include/Coordinate.h +++ b/include/Coordinate.h @@ -9,7 +9,6 @@ #include "../include/Fraction.h" -/// This namespace is the default namespace for all code in the openshot library. namespace openshot { /** diff --git a/include/DummyReader.h b/include/DummyReader.h index 55b0fdf4..1b68caf2 100644 --- a/include/DummyReader.h +++ b/include/DummyReader.h @@ -25,9 +25,10 @@ using namespace std; namespace openshot { /** - * @brief This class is used as a simple, dummy reader, which always returns a blank frame, and - * can be created with any framerate or samplerate. This is useful in unit tests that need to test - * different framerates or samplerates. + * @brief This class is used as a simple, dummy reader, which always returns a blank frame. + * + * A dummy reader can be created with any framerate or samplerate. This is useful in unit + * tests that need to test different framerates or samplerates. */ class DummyReader : public ReaderBase { diff --git a/include/FFmpegReader.h b/include/FFmpegReader.h index ef3ab809..6510d2ad 100644 --- a/include/FFmpegReader.h +++ b/include/FFmpegReader.h @@ -50,14 +50,17 @@ using namespace std; namespace openshot { - /// This struct holds the associated video frame and starting sample # for an audio packet. - /// Because audio packets do not match up with video frames, this helps determine exactly - /// where the audio packet's samples belong. - struct audio_packet_location + /** + * @brief This struct holds the associated video frame and starting sample # for an audio packet. + * + * Because audio packets do not match up with video frames, this helps determine exactly + * where the audio packet's samples belong. + */ + struct AudioLocation { int frame; int sample_start; - int is_near(audio_packet_location location, int samples_per_frame, int amount); + int is_near(AudioLocation location, int samples_per_frame, int amount); }; /** @@ -96,7 +99,7 @@ namespace openshot map frames; map processing_video_frames; map processing_audio_frames; - audio_packet_location previous_packet_location; + AudioLocation previous_packet_location; // DEBUG VARIABLES (FOR AUDIO ISSUES) bool display_debug; @@ -142,7 +145,7 @@ namespace openshot tr1::shared_ptr CreateFrame(int requested_frame); /// Calculate Starting video frame and sample # for an audio PTS - audio_packet_location GetAudioPTSLocation(int pts); + AudioLocation GetAudioPTSLocation(int pts); /// Get an AVFrame (if any) bool GetAVFrame(); diff --git a/include/FFmpegWriter.h b/include/FFmpegWriter.h index 9b83c822..be7589f8 100644 --- a/include/FFmpegWriter.h +++ b/include/FFmpegWriter.h @@ -32,7 +32,7 @@ namespace openshot /** * This enumeration designates which a type of stream when encoding */ - enum Stream_Type + enum StreamType { VIDEO_STREAM, AUDIO_STREAM @@ -163,7 +163,7 @@ namespace openshot Fraction pixel_ratio, bool interlaced, bool top_field_first, int bit_rate); /// Set custom options (some codecs accept additional params) - void SetOption(Stream_Type stream, string name, string value); + void SetOption(StreamType stream, string name, string value); /// Write the file header (after the options are set) void WriteHeader(); diff --git a/include/FrameMapper.h b/include/FrameMapper.h index a660878e..7e214262 100644 --- a/include/FrameMapper.h +++ b/include/FrameMapper.h @@ -29,7 +29,7 @@ namespace openshot * needed to remove artificial fields added when converting between 24 fps (film) * and television fps (29.97 fps NTSC or 25 fps PAL). */ - enum Pulldown_Method + enum PulldownType { PULLDOWN_CLASSIC, // Classic 2:3:2:3 pull-down PULLDOWN_ADVANCED, // Advanced 2:3:3:2 pull-down (minimal dirty frames) @@ -109,7 +109,7 @@ namespace openshot bool field_toggle; // Internal odd / even toggle (used when building the mapping) Framerate original; // The original frame rate Framerate target; // The target frame rate - Pulldown_Method pulldown; // The pull-down technique + PulldownType pulldown; // The pull-down technique ReaderBase *reader; // The source video reader Cache final_cache; // Cache of actual Frame objects @@ -128,7 +128,7 @@ namespace openshot public: /// Default constructor for FrameMapper class - FrameMapper(ReaderBase *reader, Framerate target, Pulldown_Method pulldown); + FrameMapper(ReaderBase *reader, Framerate target, PulldownType pulldown); /// Close the internal reader void Close(); diff --git a/include/KeyFrame.h b/include/KeyFrame.h index 1bd2fb79..1a1b7aed 100644 --- a/include/KeyFrame.h +++ b/include/KeyFrame.h @@ -82,7 +82,7 @@ namespace openshot { void AddPoint(float x, float y); /// Add a new point on the key-frame, with a specific interpolation type - void AddPoint(float x, float y, Interpolation_Type interpolate); + void AddPoint(float x, float y, InterpolationType interpolate); /// Set the handles, used for smooth curves. The handles are based on the surrounding points. void SetHandles(Point current); diff --git a/include/OpenShot.h b/include/OpenShot.h index e2e7f4bc..01b78d99 100644 --- a/include/OpenShot.h +++ b/include/OpenShot.h @@ -8,7 +8,7 @@ * * @mainpage OpenShot Video Editing Library C++ API * - * Welcome to the OpenShot Video Editing Library C++ API | libopenshot. This library was developed to + * Welcome to the OpenShot Video Editing Library (libopenshot) C++ API. This library was developed to * make high-quality video editing and animation solutions freely available to the world. With a focus * on stability, performance, and ease-of-use, we believe libopenshot is the best cross-platform, * open-source video editing library in the world. This library powers diff --git a/include/Point.h b/include/Point.h index 891a0cbf..42b710a2 100644 --- a/include/Point.h +++ b/include/Point.h @@ -16,7 +16,7 @@ namespace openshot * point and this one. Bezier is a smooth curve. Linear is a straight line. Constant is * is a jump from the previous point to this one. */ - enum Interpolation_Type { + enum InterpolationType { BEZIER, LINEAR, CONSTANT @@ -28,7 +28,7 @@ namespace openshot * automatically, to achieve the smoothest curves. MANUAL will leave the handles * alone, making it the responsibility of the user to set them. */ - enum Handle_Type { + enum HandleType { AUTO, MANUAL }; @@ -56,8 +56,8 @@ namespace openshot Coordinate co; ///< This is the primary coordinate Coordinate handle_left; ///< This is the left handle coordinate Coordinate handle_right; ///< This is the right handle coordinate - Interpolation_Type interpolation; ///< This is the interpolation mode - Handle_Type handle_type; ///< This is the handle mode + InterpolationType interpolation; ///< This is the interpolation mode + HandleType handle_type; ///< This is the handle mode /// Constructor which creates a single coordinate at X=0 Point(float y); @@ -66,16 +66,16 @@ namespace openshot Point(float x, float y); /// Constructor which also creates a Point and sets the X,Y, and interpolation of the Point. - Point(float x, float y, Interpolation_Type interpolation); + Point(float x, float y, InterpolationType interpolation); // Constructor which takes a coordinate Point(Coordinate co); // Constructor which takes a coordinate and interpolation mode - Point(Coordinate co, Interpolation_Type interpolation); + Point(Coordinate co, InterpolationType interpolation); // Constructor which takes a coordinate, interpolation mode, and handle type - Point(Coordinate co, Interpolation_Type interpolation, Handle_Type handle_type); + Point(Coordinate co, InterpolationType interpolation, HandleType handle_type); /** * Set the left and right handles to the same Y coordinate as the primary diff --git a/include/Timeline.h b/include/Timeline.h index 92cfe4a9..7e381593 100644 --- a/include/Timeline.h +++ b/include/Timeline.h @@ -34,7 +34,7 @@ using namespace openshot; namespace openshot { /// Comparison method for sorting clip pointers (by Position and Layer) - struct compare_clip_pointers{ + struct CompareClips{ bool operator()( Clip* lhs, Clip* rhs){ return lhs->Position() <= rhs->Position() && lhs->Layer() < rhs->Layer(); }}; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 95f32112..46be5fc7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -29,7 +29,7 @@ include_directories(${SDL_INCLUDE_DIR}) ################# QT4 ################### # Find QT4 libraries -SET(QT_QMAKE_EXECUTABLE '/usr/bin/qmake-qt4') # DEBUB, WORK-AROUND: Force the use of QT4 (when multiple versions are installed) +#SET(QT_QMAKE_EXECUTABLE '/usr/bin/qmake-qt4') # DEBUB, WORK-AROUND: Force the use of QT4 (when multiple versions are installed) FIND_PACKAGE(Qt4) # Include Qt headers (needed for compile) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index b9aaa4a9..d6f8c26a 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -67,7 +67,7 @@ void FFmpegReader::InitScalers() } // This struct holds the associated video frame and starting sample # for an audio packet. -int audio_packet_location::is_near(audio_packet_location location, int samples_per_frame, int amount) +int AudioLocation::is_near(AudioLocation location, int samples_per_frame, int amount) { // Is frame even close to this one? if (abs(location.frame - frame) >= 2) @@ -523,7 +523,7 @@ tr1::shared_ptr FFmpegReader::ReadStream(int requested_frame) UpdatePTSOffset(false); // Determine related video frame and starting sample # from audio PTS - audio_packet_location location = GetAudioPTSLocation(packet->pts); + AudioLocation location = GetAudioPTSLocation(packet->pts); // Process Audio Packet ProcessAudioPacket(requested_frame, location.frame, location.sample_start); @@ -1197,7 +1197,7 @@ int FFmpegReader::ConvertFrameToAudioPTS(int frame_number) } // Calculate Starting video frame and sample # for an audio PTS -audio_packet_location FFmpegReader::GetAudioPTSLocation(int pts) +AudioLocation FFmpegReader::GetAudioPTSLocation(int pts) { // Apply PTS offset pts = pts + audio_pts_offset; @@ -1229,7 +1229,7 @@ audio_packet_location FFmpegReader::GetAudioPTSLocation(int pts) sample_start = 0; // Prepare final audio packet location - audio_packet_location location = {whole_frame, sample_start}; + AudioLocation location = {whole_frame, sample_start}; // Compare to previous audio packet (and fix small gaps due to varying PTS timestamps) if (previous_packet_location.frame != -1 && location.is_near(previous_packet_location, samples_per_frame, samples_per_frame)) diff --git a/src/FFmpegWriter.cpp b/src/FFmpegWriter.cpp index c0fda1fa..d7f4710e 100644 --- a/src/FFmpegWriter.cpp +++ b/src/FFmpegWriter.cpp @@ -175,7 +175,7 @@ void FFmpegWriter::SetAudioOptions(bool has_audio, string codec, int sample_rate } // Set custom options (some codecs accept additional params) -void FFmpegWriter::SetOption(Stream_Type stream, string name, string value) +void FFmpegWriter::SetOption(StreamType stream, string name, string value) { // Declare codec context AVCodecContext *c = NULL; diff --git a/src/FrameMapper.cpp b/src/FrameMapper.cpp index cdd179fe..d6053f83 100644 --- a/src/FrameMapper.cpp +++ b/src/FrameMapper.cpp @@ -9,7 +9,7 @@ using namespace std; using namespace openshot; -FrameMapper::FrameMapper(ReaderBase *reader, Framerate target, Pulldown_Method pulldown) : +FrameMapper::FrameMapper(ReaderBase *reader, Framerate target, PulldownType pulldown) : reader(reader), target(target), pulldown(pulldown), final_cache(820 * 1024) { diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index 420932e6..c0fb5c66 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -79,7 +79,7 @@ void Keyframe::AddPoint(float x, float y) } // Add a new point on the key-frame, with a specific interpolation type -void Keyframe::AddPoint(float x, float y, Interpolation_Type interpolate) +void Keyframe::AddPoint(float x, float y, InterpolationType interpolate) { // Create a point Point new_point(x, y, interpolate); diff --git a/src/Main.cpp b/src/Main.cpp index ef9b5f7a..be91e52b 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -12,10 +12,10 @@ using namespace openshot; using namespace tr1; -void FrameReady(int number) -{ - cout << "Frame #: " << number << " is ready!" << endl; -} +//void FrameReady(int number) +//{ +// cout << "Frame #: " << number << " is ready!" << endl; +//} int main(int argc, char* argv[]) { diff --git a/src/Point.cpp b/src/Point.cpp index a33e0539..6b6a59cc 100644 --- a/src/Point.cpp +++ b/src/Point.cpp @@ -29,8 +29,8 @@ Point::Point(float x, float y) : } // Constructor which also creates a Point and sets the X,Y, and interpolation of the Point. -Point::Point(float x, float y, Interpolation_Type interpolation) : - handle_type(AUTO), interpolation(interpolation) { +Point::Point(float x, float y, InterpolationType interpolation) : + handle_type(AUTO), interpolation(interpolation) { // set new coorinate co = Coordinate(x, y); @@ -44,13 +44,13 @@ Point::Point(Coordinate co) : Initialize_Handles(); } -Point::Point(Coordinate co, Interpolation_Type interpolation) : +Point::Point(Coordinate co, InterpolationType interpolation) : co(co), interpolation(interpolation), handle_type(AUTO) { // set handles Initialize_Handles(); } -Point::Point(Coordinate co, Interpolation_Type interpolation, Handle_Type handle_type) : +Point::Point(Coordinate co, InterpolationType interpolation, HandleType handle_type) : co(co), interpolation(interpolation), handle_type(handle_type) { // set handles Initialize_Handles(); diff --git a/src/Timeline.cpp b/src/Timeline.cpp index 3ebaf6f1..83676aa2 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -298,7 +298,7 @@ void Timeline::update_closed_clips() void Timeline::SortClips() { // sort clips - clips.sort(compare_clip_pointers()); + clips.sort(CompareClips()); } // Close the reader (and any resources it was consuming) diff --git a/src/examples/test.py b/src/examples/test.py deleted file mode 100644 index 7f11dfb1..00000000 --- a/src/examples/test.py +++ /dev/null @@ -1,33 +0,0 @@ -import openshot -import gtk - -# Create Reader -r = openshot.FFmpegReader("/home/jonathan/Videos/sintel-1024-stereo.mp4") - -# Create Player -p = openshot.Player() - -# Set the Reader -p.SetReader(r) - -# Create callback method -def FrameDone(frame, width, height, pixels): - print "------------" - print "frame ready for display: %d" % frame - - # Create pixbuf - #pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, width, height) - #pixel_array = pixbuf.get_pixels_array() - - # Loop through pixel array of pixbuf, and set values - #for row in range(height): - # for col in range(width): - # for color in range(3): - # pixel_array[row][col][color] = pixels[row][col][color] - - # Save pixbuf for debugging - #pixbuf.save("test.png", "png") - print "pixbuf created for frame: %d" % frame - -# Hook up python callback -p.set_pymethod(FrameDone) \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 72a3fb26..ec2139a6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -35,7 +35,7 @@ include_directories(${SDL_INCLUDE_DIR}) ################# QT4 ################### # Find QT4 libraries -SET(QT_QMAKE_EXECUTABLE '/usr/bin/qmake-qt4') # DEBUB, WORK-AROUND: Force the use of QT4 (when multiple versions are installed) +#SET(QT_QMAKE_EXECUTABLE '/usr/bin/qmake-qt4') # DEBUB, WORK-AROUND: Force the use of QT4 (when multiple versions are installed) FIND_PACKAGE(Qt4 REQUIRED) # Include Qt headers (needed for compile) diff --git a/tests/Point_Tests.cpp b/tests/Point_Tests.cpp index e6dcf931..2fba71e0 100644 --- a/tests/Point_Tests.cpp +++ b/tests/Point_Tests.cpp @@ -29,7 +29,7 @@ TEST(Point_Constructor_With_Coordinate_And_LINEAR_Interpolation) { // Create a point with a coordinate and interpolation Coordinate c1(3,9); - Interpolation_Type interp = LINEAR; + InterpolationType interp = LINEAR; openshot::Point p1(c1, interp); CHECK_EQUAL(3, c1.X); @@ -41,7 +41,7 @@ TEST(Point_Constructor_With_Coordinate_And_BEZIER_Interpolation) { // Create a point with a coordinate and interpolation Coordinate c1(3,9); - Interpolation_Type interp = BEZIER; + InterpolationType interp = BEZIER; openshot::Point p1(c1, interp); CHECK_EQUAL(3, p1.co.X); @@ -53,7 +53,7 @@ TEST(Point_Constructor_With_Coordinate_And_CONSTANT_Interpolation) { // Create a point with a coordinate and interpolation Coordinate c1(2,8); - Interpolation_Type interp = CONSTANT; + InterpolationType interp = CONSTANT; openshot::Point p1(c1, interp); CHECK_EQUAL(2, p1.co.X);