repo_name
stringlengths
5
122
path
stringlengths
3
232
text
stringlengths
6
1.05M
Tamookk/Basil
Basil/include/Debug/Timer.h
/* * Declares a class for timing how long things take in Basil. */ #pragma once #include <chrono> namespace Basil { template <typename Fn> class Timer { public: Timer(const char* name, Fn&& fn) : func(fn) { // Initialise variables this->name = name; stopped = false; startTimepoint = std::chrono::high_resolution_clock::now(); } ~Timer() { if (!stopped) stop(); } void stop() { std::chrono::time_point<std::chrono::steady_clock> endTimepoint = std::chrono::high_resolution_clock::now(); long long start = std::chrono::time_point_cast<std::chrono::microseconds>(startTimepoint).time_since_epoch().count(); long long end = std::chrono::time_point_cast<std::chrono::microseconds>(endTimepoint).time_since_epoch().count(); stopped = true; float duration = (end - start) * 0.001f; func({ name, duration }); } private: const char* name; Fn func; std::chrono::time_point<std::chrono::steady_clock> startTimepoint; bool stopped; }; }
Tamookk/Basil
Basil/include/Renderer/IndexBuffer.h
<gh_stars>0 /* * This header file defines a class for creating index buffers. */ #pragma once #include <cstdint> namespace Basil { class IndexBuffer { public: virtual ~IndexBuffer() {} virtual void bind() const = 0; virtual void unbind() const = 0; virtual uint32_t getSize() const = 0; static Shared<IndexBuffer> create(std::vector<uint32_t>& indices); }; }
Tamookk/Basil
Basil/include/Renderer/Texture.h
/* * This header file contains the base class for all textures. */ #pragma once namespace Basil { class Texture { public: virtual ~Texture() {} virtual uint32_t getWidth() const = 0; virtual uint32_t getHeight() const = 0; virtual uint32_t getRendererID() const = 0; virtual void setData(void* data, uint32_t size) = 0; virtual void bind(unsigned int slot = 0) const = 0; virtual bool isTextureLoaded() const = 0; virtual bool operator==(const Texture& other) const = 0; }; }
Tamookk/Basil
Basil/include/Events/KeyEvent.h
/* * This header defines key event classes. */ #pragma once #include "Events/Event.h" namespace Basil { class KeyPressedEvent : public Event { public: KeyPressedEvent(int keycode, int repeatCount); int getKeycode() const; int getRepeatCount() const; virtual EventType getEventType() const override; static EventType getStaticType(); virtual const char* getName() const override; virtual std::string toString() const override; virtual int getCategory() const override; private: int keycode; int repeatCount; }; class KeyReleasedEvent : public Event { public: KeyReleasedEvent(int keycode); int getKeycode() const; virtual EventType getEventType() const override; static EventType getStaticType(); virtual const char* getName() const override; virtual std::string toString() const override; virtual int getCategory() const override; private: int keycode; }; class KeyTypedEvent : public Event { public: KeyTypedEvent(int keycode); int getKeycode() const; virtual EventType getEventType() const override; static EventType getStaticType(); virtual const char* getName() const override; virtual std::string toString() const override; virtual int getCategory() const override; private: int keycode; }; }
Tamookk/Basil
Basil/include/Core/MouseCodes.h
<filename>Basil/include/Core/MouseCodes.h /* * This header file contains mouse button codes for the Basil game engine. */ #pragma once namespace Basil { typedef enum class MouseCode : uint16_t { // From glfw3.h Button0 = 0, Button1 = 1, Button2 = 2, Button3 = 3, Button4 = 4, Button5 = 5, Button6 = 6, Button7 = 7, ButtonLast = Button7, ButtonLeft = Button0, ButtonRight = Button1, ButtonMiddle = Button2 } Mouse; inline std::ostream& operator<<(std::ostream& os, MouseCode mouseCode) { os << static_cast<int32_t>(mouseCode); return os; } } // From glfw3.h #define BASIL_MOUSE_BUTTON_0 ::Basil::MouseCode::Button0 #define BASIL_MOUSE_BUTTON_1 ::Basil::MouseCode::Button1 #define BASIL_MOUSE_BUTTON_2 ::Basil::MouseCode::Button2 #define BASIL_MOUSE_BUTTON_3 ::Basil::MouseCode::Button3 #define BASIL_MOUSE_BUTTON_4 ::Basil::MouseCode::Button4 #define BASIL_MOUSE_BUTTON_5 ::Basil::MouseCode::Button5 #define BASIL_MOUSE_BUTTON_6 ::Basil::MouseCode::Button6 #define BASIL_MOUSE_BUTTON_7 ::Basil::MouseCode::Button7 #define BASIL_MOUSE_BUTTON_LEFT ::Basil::MouseCode::ButtonLeft #define BASIL_MOUSE_BUTTON_RIGHT ::Basil::MouseCode::ButtonRight #define BASIL_MOUSE_BUTTON_MIDDLE ::Basil::MouseCode::ButtonMiddle
Tamookk/Basil
Basil/include/Events/Event.h
<reponame>Tamookk/Basil /* * This header defines classes and components for event handling. */ #pragma once #include "pch.h" #include "Core/Core.h" namespace Basil { // Events are currently processed as they happen // Type of event enum class EventType { None = 0, WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, AppTick, AppUpdate, AppRender, KeyPressed, KeyReleased, KeyTyped, MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled }; // Category of event enum EventCategory { None = 0, ApplicationEvent = 0b00000001, InputEvent = 0b00000010, KeyboardEvent = 0b00000100, MouseEvent = 0b00001000, MouseButtonEvent = 0b00010000 }; class Event { friend class EventDispatcher; public: Event(); virtual EventType getEventType() const = 0; virtual const char* getName() const = 0; virtual std::string toString() const; virtual int getCategory() const = 0; bool isInCategory(EventCategory category); bool handled; }; // For dispatching events class EventDispatcher { public: EventDispatcher(Event& e); template <typename T, typename F> bool dispatch(const F& eventFunction) { if (event.getEventType() == T::getStaticType()) { event.handled |= eventFunction(static_cast<T&>(event)); return true; } return false; } private: Event& event; }; // Define << operator for events inline std::ostream& operator<<(std::ostream& os, const Event& e) { return os << e.toString(); } }
Tamookk/Basil
Basil/include/Platform/OpenGL/OpenGLFramebuffer.h
/* * This header file declares the OpenGL-specific implementation of Framebuffer. */ #pragma once #include "Renderer/Framebuffer.h" namespace Basil { class OpenGLFramebuffer : public Framebuffer { public: OpenGLFramebuffer(const FramebufferSpecification& spec); ~OpenGLFramebuffer(); void invalidate(); void bind() override; void unbind() override; void resize(uint32_t width, uint32_t height) override; int readPixel(uint32_t attachmentIndex, int x, int y) override; void clearAttachment(uint32_t attachmentIndex, int value) override; uint32_t getColorAttachmentRendererID(uint32_t index = 0) const override; const FramebufferSpecification& getSpecification() const override; private: uint32_t rendererID; FramebufferSpecification specification; std::vector<FramebufferTextureSpecification> colorAttachmentSpecifications; FramebufferTextureSpecification depthAttachmentSpecification; std::vector<uint32_t> colorAttachments; uint32_t depthAttachment; }; }
Tamookk/Basil
Basil/include/Renderer/ShaderLibrary.h
<gh_stars>0 /* * */ #pragma once #include <unordered_map> #include "Core/Core.h" #include "Renderer/Shader.h" namespace Basil { class ShaderLibrary { public: void add(const Shared<Shader>& shader); void add(const std::string& name, const Shared<Shader>& shader); Shared<Shader> load(const std::string& filePath); Shared<Shader> load(const std::string& name, const std::string& filePath); Shared<Shader> get(const std::string& name); bool exists(const std::string& name); private: std::unordered_map<std::string, Shared<Shader>> shaders; }; }
Tamookk/Basil
Basil/include/Scene/Entity.h
<filename>Basil/include/Scene/Entity.h<gh_stars>0 /* * This header file declares the entity class, used for the ECS. */ #pragma once #include "Core/UUID.h" #include "Scene/Component.h" #include "Scene/Scene.h" #include <entt.hpp> namespace Basil { class Entity { public: Entity() = default; Entity(entt::entity handle, Scene* scene); Entity(const Entity& other) = default; // Add a component template <typename T, typename ... Args> T& addComponent(Args&&... args) { ASSERT(!hasComponent<T>(), "Entity already has component."); T& component = scene->registry.emplace<T>(entity, std::forward<Args>(args)...); scene->onComponentAdded<T>(*this, component); return component; } // Add or replace a component template<typename T, typename... Args> T& addOrReplaceComponent(Args&&... args) { T& component = scene->registry.emplace_or_replace<T>(entity, std::forward<Args>(args)...); scene->onComponentAdded<T>(*this, component); return component; } // Get a component template <typename T> T& getComponent() { ASSERT(hasComponent<T>(), "Entity does not have component."); return scene->registry.get<T>(entity); } // Return whether an entity has a component template <typename T> bool hasComponent() { return scene->registry.all_of<T>(entity); } // Remove a component template <typename T> void removeComponent() { ASSERT(hasComponent<T>(), "Entity does not have component."); scene->registry.remove<T>(entity); } operator bool() const; operator entt::entity() const; operator uint32_t() const; UUID getUUID(); const std::string& getName(); bool operator==(const Entity& other) const; bool operator!=(const Entity& other) const; private: entt::entity entity = entt::null; Scene* scene = nullptr; }; }
Tamookk/Basil
Basil/include/Platform/OpenGL/OpenGLTexture2D.h
<filename>Basil/include/Platform/OpenGL/OpenGLTexture2D.h /* * This header files declares the OpenGL implementation of Texture2D. */ #pragma once #include "Renderer/Texture2D.h" #include <glad/glad.h> namespace Basil { class OpenGLTexture2D : public Texture2D { public: OpenGLTexture2D(const std::string& path); OpenGLTexture2D(uint32_t width, uint32_t height); ~OpenGLTexture2D(); uint32_t getWidth() const override; uint32_t getHeight() const override; uint32_t getRendererID() const override; void setData(void* data, uint32_t size) override; void bind(unsigned int slot = 0) const override; bool isTextureLoaded() const override; bool operator==(const Texture& other) const override; private: std::string path; bool isLoaded; uint32_t width; uint32_t height; uint32_t rendererID; GLenum internalFormat; GLenum dataFormat; }; }
Tamookk/Basil
Basil/include/Scene/SceneCamera.h
/* * This header file declares a class for a Scene Camera. */ #pragma once #include "Renderer/Camera.h" namespace Basil { class SceneCamera : public Camera { public: enum class CameraType { Perspective = 0, Orthographic = 1 }; public: SceneCamera(); ~SceneCamera() = default; void setPerspective(float verticalFOV, float nearClip, float farClip); void setOrthographic(float size, float nearClip, float farClip); void setViewportSize(uint32_t width, uint32_t height); float getPerspectiveVerticalFOV() const; void setPerspectiveVerticalFOV(float verticalFOV); float getPerspectiveNearClip() const; void setPerspectiveNearClip(float nearClip); float getPerspectiveFarClip() const; void setPerspectiveFarClip(float farClip); float getOrthographicSize() const; void setOrthographicSize(float size); float getOrthographicNearClip() const; void setOrthographicNearClip(float nearClip); float getOrthographicFarClip() const; void setOrthographicFarClip(float farClip); CameraType getCameraType() const; void setCameraType(CameraType type); private: void recalculateProjection(); CameraType cameraType; float perspectiveFOV; float perspectiveNear; float perspectiveFar; float orthographicSize; float orthographicNear; float orthographicFar; float aspectRatio; }; }
Tamookk/Basil
Basil/include/Scene/Scene.h
/* * This header file declares a class for game scenes. */ #pragma once #include "Core/Timestep.h" #include "Core/UUID.h" #include "Renderer/EditorCamera.h" #include <entt.hpp> class b2World; namespace Basil { class Entity; class Scene { public: Scene(); ~Scene(); static Shared<Scene> copy(Shared<Scene> other); Entity createEntity(const std::string& name = std::string()); Entity createEntityWithUUID(UUID uuid, const std::string& name = std::string()); void destroyEntity(Entity entity); void onRuntimeStart(); void onRuntimeStop(); entt::registry& reg(); void onUpdateRuntime(Timestep timeStep); void onUpdateEditor(Timestep timeStep, EditorCamera& camera); void onViewportResize(uint32_t width, uint32_t height); void duplicateEntity(Entity entity); Entity getPrimaryCameraEntity(); template<typename... Components> auto getAllEntitiesWith() { return registry.view<Components...>(); } private: template <typename T> void onComponentAdded(Entity entity, T& component); entt::registry registry; uint32_t viewportWidth; uint32_t viewportHeight; b2World* box2DWorld; friend class Entity; friend class PropertiesPanel; friend class SceneHierarchyPanel; friend class SceneSerializer; }; }
Tamookk/Basil
Basil/include/Renderer/Camera.h
<reponame>Tamookk/Basil /* * Declares a generic camera class. */ #pragma once #include <glm/glm.hpp> namespace Basil { class Camera { public: // TODO: move definition to own cpp file Camera() = default; Camera(const glm::mat4& projection) : projection(projection) {} virtual ~Camera() = default; const glm::mat4& getProjection() const { return projection; } protected: glm::mat4 projection = glm::mat4(1.0f); }; }
Tamookk/Basil
Basil/include/Platform/Windows/WindowsWindow.h
/* * This header file contains an extension of the Window class that is platform-specific to Windows. */ #pragma once #include "Core/Window.h" #include "Events/ApplicationEvent.h" #include "Events/KeyEvent.h" #include "Events/MouseEvent.h" #include "Platform/OpenGL/OpenGLContext.h" #include "Renderer/GraphicsContext.h" namespace Basil { class WindowsWindow : public Window { public: WindowsWindow(const WindowProps& props); virtual ~WindowsWindow(); void onUpdate() override; unsigned int getWidth() const override; unsigned int getHeight() const override; void setEventCallback(const EventCallbackFunction& callback) override; void setVsync(bool enabled) override; bool isVsync() const override; void* getNativeWindow() const override; private: struct WindowData { std::string title; unsigned int width; unsigned int height; bool vsync; EventCallbackFunction eventCallbackFunction; }; virtual void init(const WindowProps& props); virtual void shutdown(); GLFWwindow* window; Unique<GraphicsContext> context; WindowData data; }; }
Tamookk/Basil
Basil/include/Core/Timestep.h
/* * This header file contains a class for keeping track of time. */ #pragma once namespace Basil { class Timestep { public: Timestep(float time); float getSeconds() const; float getMilliseconds() const; operator float() const { return time; } private: float time; }; }
Tamookk/Basil
Basil/include/Core/LayerStack.h
<gh_stars>0 /* * This header file is for defining the LayerStack class, which is used to abstract adding and * removing layers from a layer vector. */ #pragma once #include <vector> #include "Core/Core.h" #include "Core/Layer.h" namespace Basil { class LayerStack { public: LayerStack(); ~LayerStack(); void pushLayer(Layer* layer); void pushOverlay(Layer* layer); void popLayer(Layer* layer); void popOverlay(Layer* layer); std::vector<Layer*>::iterator begin(); std::vector<Layer*>::iterator end(); private: std::vector<Layer*> layers; unsigned int layerInsertIndex; }; }
Tamookk/Basil
Basil/include/Core/Timer.h
/* * This header file declares a class for a basic timer. */ #pragma once #include <chrono> namespace Basil { class Timer { public: Timer(); void reset(); float elapsed(); float elapsedMillis(); private: std::chrono::time_point<std::chrono::high_resolution_clock> start; }; }
Tamookk/Basil
Basil/include/Renderer/BufferElement.h
/* * This header file declares a class used for holding data on a buffer element. * This header file also defines an enum class that defines the different * types of data that can be passed to shaders. */ #pragma once #include <cstdint> #include <string> // Define the shader data types enum class ShaderDataType { None = 0, Float, Float2, Float3, Float4, Mat3, Mat4, Int, Int2, Int3, Int4, Bool }; // A function for getting the size of the given shader data type static uint32_t ShaderDataTypeSize(ShaderDataType type); // Define a struct for a buffer element struct BufferElement { std::string name; ShaderDataType type; uint32_t size; uint32_t offset; bool normalised; BufferElement(const std::string& name, ShaderDataType type, bool normalised = false); uint32_t getComponentCount() const; };
Tamookk/Basil
Basil/include/Renderer/VertexArray.h
<gh_stars>0 /* * This header file declares a class used for creating and using * vertex array objects. */ #pragma once #include "Renderer/IndexBuffer.h" #include "Renderer/VertexBuffer.h" namespace Basil { class VertexArray { public: virtual ~VertexArray() {} virtual void bind() const = 0; virtual void unbind() const = 0; virtual void addVertexBuffer(const Shared<VertexBuffer>& vbo) = 0; virtual const std::vector<Shared<VertexBuffer>>& getVertexBuffers() const = 0; virtual void setIndexBuffer(const Shared<IndexBuffer>& ibo) = 0; virtual const Shared<IndexBuffer>& getIndexBuffer() const = 0; static Shared<VertexArray> create(); }; }
Tamookk/Basil
Pesto/include/EditorLayer.h
<gh_stars>0 /* * Declares a class for testing 2D rendering. */ #pragma once #include "Panels/ContentBrowserPanel.h" #include "Panels/PropertiesPanel.h" #include "Panels/SceneHierarchyPanel.h" #include "Renderer/EditorCamera.h" #include "Core/Basil.h" namespace Basil { class EditorLayer : public Layer { public: enum class SceneState { Edit = 0, Play = 1 }; public: EditorLayer(); virtual ~EditorLayer() {} void onAttach() override; void onDetach() override; void onUpdate(Timestep timeStep) override; void onEvent(Event& e) override; void onImGuiRender() override; private: bool onKeyPressed(KeyPressedEvent& e); bool onMouseButtonPressed(MouseButtonPressedEvent& e); void onOverlayRender(); void newScene(); void openScene(); void openScene(const std::filesystem::path path); void saveScene(); void saveSceneAs(); void serializeScene(Shared<Scene> scene, const std::filesystem::path& path); void onScenePlay(); void onSceneStop(); void onDuplicateEntity(); // -- UI -- // void UI_Toolbar(); // -- Panels -- // ContentBrowserPanel contentBrowserPanel; PropertiesPanel propertiesPanel; SceneHierarchyPanel sceneHierarchyPanel; Shared<Framebuffer> framebuffer; Shared<Scene> activeScene; Shared<Scene> editorScene; std::filesystem::path editorScenePath; glm::vec2 viewportSize = { 0.0f, 0.0f }; glm::vec2 viewportBounds[2]; glm::vec4 squareColor = { 0.2f, 0.3f, 0.8f, 1.0f }; EditorCamera editorCamera; Entity squareEntity; Entity cameraEntity; Entity secondCameraEntity; Entity hoveredEntity; bool viewportFocused; bool viewportHovered; bool primaryCamera = true; bool showPhysicsColliders; int gizmoType; SceneState sceneState; // -- Editor Resources -- // Shared<Texture2D> iconPlay; Shared<Texture2D> iconStop; }; }
Tamookk/Basil
Basil/include/Platform/OpenGL/OpenGLVertexArray.h
/* * This header file contains a class for the OpenGL-specific implementation of * VertexArray.h. */ #pragma once #include "Renderer/VertexArray.h" #include <glad/glad.h> namespace Basil { class OpenGLVertexArray : public VertexArray { public: OpenGLVertexArray(); ~OpenGLVertexArray(); void bind() const override; void unbind() const override; void addVertexBuffer(const Shared<VertexBuffer>& vbo) override; void setIndexBuffer(const Shared<IndexBuffer>& ibo) override; const std::vector<Shared<VertexBuffer>>& getVertexBuffers() const override; const Shared<IndexBuffer>& getIndexBuffer() const override; private: unsigned int vao; std::vector<Shared<VertexBuffer>> vbos; Shared<IndexBuffer> ibo; }; }
Tamookk/Basil
Basil/include/Core/Log.h
<gh_stars>0 /* * This class is for game engine and client logging. */ #pragma once #include "Core.h" #define GLM_ENABLE_EXPERIMENTAL #include <glm/gtx/string_cast.hpp> #include <spdlog/spdlog.h> #include <spdlog/fmt/ostr.h> #include <spdlog/sinks/basic_file_sink.h> #include <spdlog/sinks/stdout_color_sinks.h> namespace Basil { class Log { public: static void init(); inline static Shared<spdlog::logger>& getClientLogger() { return clientLogger; } inline static Shared<spdlog::logger>& getEngineLogger() { return engineLogger; } private: static Shared<spdlog::logger> clientLogger; static Shared<spdlog::logger> engineLogger; }; } // Allow logging of GLM vectors, matrices, and quaternions template<typename OStream, glm::length_t L, typename T, glm::qualifier Q> inline OStream& operator<<(OStream& os, const glm::vec<L, T, Q>& vector) { return os << glm::to_string(vector); } template<typename OStream, glm::length_t C, glm::length_t R, typename T, glm::qualifier Q> inline OStream& operator<<(OStream& os, const glm::mat<C, R, T, Q>& matrix) { return os << glm::to_string(matrix); } template<typename OStream, typename T, glm::qualifier Q> inline OStream& operator<<(OStream& os, const glm::qua<T, Q>& quaternion) { return os << glm::to_string(quaternion); } // Define client logging macros #define LOG_CLIENT_TRACE(...) Basil::Log::getClientLogger()->trace(__VA_ARGS__); #define LOG_CLIENT_INFO(...) Basil::Log::getClientLogger()->info(__VA_ARGS__); #define LOG_CLIENT_WARN(...) Basil::Log::getClientLogger()->warn(__VA_ARGS__); #define LOG_CLIENT_ERROR(...) Basil::Log::getClientLogger()->error(__VA_ARGS__); #define LOG_CLIENT_FATAL(...) Basil::Log::getClientLogger()->critical(__VA_ARGS__); // Define engine logging macros #define LOG_TRACE(...) Basil::Log::getEngineLogger()->trace(__VA_ARGS__); #define LOG_INFO(...) Basil::Log::getEngineLogger()->info(__VA_ARGS__); #define LOG_WARN(...) Basil::Log::getEngineLogger()->warn(__VA_ARGS__); #define LOG_ERROR(...) Basil::Log::getEngineLogger()->error(__VA_ARGS__); #define LOG_FATAL(...) Basil::Log::getEngineLogger()->critical(__VA_ARGS__);
Tamookk/Basil
Basil/include/Debug/Instrumentor.h
<filename>Basil/include/Debug/Instrumentor.h /* * Declares a class for writing profiling data to a JSON file. */ #pragma once #include <algorithm> #include <chrono> #include <fstream> #include <string> #include <thread> namespace Basil { struct ProfileResult { std::string name; long long start; long long end; std::thread::id threadID; }; struct InstrumentationSession { std::string name; }; class Instrumentor { public: Instrumentor(); void beginSession(const std::string& name, const std::string& filePath = "results.json"); void endSession(); void writeProfile(const ProfileResult& result); static Instrumentor& get(); private: void writeHeader(); void writeFooter(); void internalEndSession(); InstrumentationSession* currentSession; std::ofstream outputStream; int profileCount; std::mutex mutex; }; class InstrumentationTimer { public: InstrumentationTimer(const char* name); ~InstrumentationTimer(); void stop(); private: const char* name; std::chrono::time_point<std::chrono::high_resolution_clock> startTimepoint; bool stopped; }; namespace InstrumentorUtils { template <size_t N> struct ChangeResult { char data[N]; }; template <size_t N, size_t K> constexpr auto cleanupOutputString(const char(&expr)[N], const char(&remove)[K]) { ChangeResult<N> result = {}; size_t srcIndex = 0; size_t dstIndex = 0; while (srcIndex < N) { size_t matchIndex = 0; while (matchIndex < K - 1 && srcIndex + matchIndex < N - 1 && expr[srcIndex + matchIndex] == remove[matchIndex]) matchIndex++; if (matchIndex == K - 1) srcIndex += matchIndex; result.data[dstIndex++] = expr[srcIndex] == '"' ? '\'' : expr[srcIndex]; srcIndex++; } return result; } } #define PROFILE 0 #if PROFILE #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600)) || defined(__ghs__) #define FUNC_SIG __PRETTY_FUNCTION__ #elif defined(__DMC__) && (__DMC__ >= 0x810) #define FUNC_SIG __PRETTY_FUNCTION__ #elif (defined(__FUNCSIG__) || (_MSC_VER)) #define FUNC_SIG __FUNCSIG__ #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500)) #define FUNC_SIG __FUNCTION__ #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550) #define FUNC_SIG __FUNC__ #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901) #define FUNC_SIG __func__ #elif defined(__cplusplus) && (__cplusplus >= 201103) #define FUNC_SIG __func__ #else #define FUNC_SIG "FUN_SIG unknown!" #endif #define PROFILE_BEGIN_SESSION(name, filepath) ::Basil::Instrumentor::get().beginSession(name, filepath) #define PROFILE_END_SESSION() ::Basil::Instrumentor::get().endSession() #define PROFILE_SCOPE(name) constexpr auto fixedName = ::Basil::InstrumentorUtils::cleanupOutputString(name, "__cdecl"); ::Basil::InstrumentationTimer timer##__LINE__(fixedName.data) #define PROFILE_FUNCTION() PROFILE_SCOPE(FUNC_SIG) #else #define PROFILE_BEGIN_SESSION(name, filepath) #define PROFILE_END_SESSION() #define PROFILE_SCOPE(name) #define PROFILE_FUNCTION() #endif }
Tamookk/Basil
Basil/include/Renderer/EditorCamera.h
/* * This header file declares the camera used by the editor. */ #pragma once #include "Core/Timestep.h" #include "Events/Event.h" #include "Events/MouseEvent.h" #include "Renderer/Camera.h" #include <glm/glm.hpp> namespace Basil { class EditorCamera : public Camera { public: EditorCamera() = default; EditorCamera(float fov, float aspectRatio, float nearClip, float farClip); void onUpdate(Timestep timeStep); void onEvent(Event& e); float getDistance() const; void setDistance(float distance); void setViewportSize(float width, float height); const glm::mat4& getViewMatrix() const; glm::mat4 getViewProjection() const; glm::vec3 getUpDirection() const; glm::vec3 getRightDirection() const; glm::vec3 getForwardDirection() const; const glm::vec3& getPosition() const; glm::quat getOrientation() const; float getPitch() const; float getYaw() const; private: void updateProjection(); void updateView(); bool onMouseScroll(MouseScrolledEvent& e); void mousePan(const glm::vec2& delta); void mouseRotate(const glm::vec2& delta); void mouseZoom(float delta); glm::vec3 calculatePosition() const; std::pair<float, float> panSpeed() const; float rotationSpeed() const; float zoomSpeed() const; float FOV; float aspectRatio; float nearClip; float farClip; glm::mat4 viewMatrix; glm::vec3 position = { 0.0f, 0.0f, 0.0f }; glm::vec3 focalPoint = { 0.0f, 0.0f, 0.0f }; glm::vec2 initialMousePosition = { 0.0f, 0.0f }; float distance; float pitch; float yaw; float viewportWidth; float viewportHeight; }; }
Tamookk/Basil
Basil/include/Renderer/RendererAPI.h
/* * This header file declares an interface for the renderer that will be implemented per-platform. */ #pragma once #include "Renderer/VertexArray.h" #include <glm/glm.hpp> namespace Basil { class RendererAPI { public: enum class API { None = 0, OpenGL = 1 }; virtual void init() = 0; virtual void setViewport(unsigned int x, unsigned int y, unsigned int width, unsigned int height) = 0; virtual void setClearColor(const glm::vec4& color) = 0; virtual void clear() = 0; virtual void drawIndexed(const Shared<VertexArray>& vao, uint32_t count = 0) = 0; virtual void drawLines(const Shared<VertexArray>& vao, uint32_t vertexCount) = 0; virtual void setLineWidth(float width) = 0; static API getAPI(); static Unique<RendererAPI> create(); private: static API api; }; }
Tamookk/Basil
Pesto/include/Panels/ContentBrowserPanel.h
/* * This header file declares a panel for content browsing. */ #pragma once #include <filesystem> #include "Renderer/Texture2D.h" namespace Basil { class ContentBrowserPanel { public: ContentBrowserPanel(); void onImGuiRender(); private: std::filesystem::path currentDirectory; Shared<Texture2D> directoryIcon; Shared<Texture2D> fileIcon; }; }
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/atlsecurity.h
#include <atlsecurity.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/openssl/evp.h
#include <openssl/evp.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/atlconv.h
#include <atlconv.h>
trdwll/CryptolensUE
Source/CryptolensUE/Public/CryptolensUE.h
// Russ 'trdwll' Treadwell <<EMAIL>> - 2021 #pragma once #include "CoreMinimal.h" #include "Modules/ModuleManager.h" #include "UObject/NoExportTypes.h" #include <cryptolens/Configuration_Windows.hpp> #include <cryptolens/Error.hpp> #include <cryptolens/MachineCodeComputer_static.hpp> #include <cryptolens/core.hpp> #include "CryptolensUE.generated.h" class FCryptolensUEModule : public IModuleInterface { public: /** IModuleInterface implementation */ virtual void StartupModule() override; virtual void ShutdownModule() override; private: }; UENUM(BlueprintType) enum class ELicenseFeature : uint8 { F1 UMETA(DisplayName = "Feature 1"), F2 UMETA(DisplayName = "Feature 2"), F3 UMETA(DisplayName = "Feature 3"), F4 UMETA(DisplayName = "Feature 4"), F5 UMETA(DisplayName = "Feature 5"), F6 UMETA(DisplayName = "Feature 6"), F7 UMETA(DisplayName = "Feature 7"), F8 UMETA(DisplayName = "Feature 8") }; namespace cryptolens = ::cryptolens_io::v20190401; using Cryptolens = cryptolens::basic_Cryptolens<cryptolens::Configuration_Windows<cryptolens::MachineCodeComputer_static>>; using namespace cryptolens::errors; UCLASS() class CRYPTOLENSUE_API UCryptolens : public UObject { GENERATED_BODY() public: UFUNCTION(BlueprintCallable, Category = "UCryptolens") static UCryptolensLicenseKey* GetLicenseKey(const FString& LicenseKey); protected: private: }; // tbh I'd rather do this as a struct, but we can't expose methods to BP from structs UCLASS() class CRYPTOLENSUE_API UCryptolensLicenseKey : public UObject { GENERATED_BODY() public: UCryptolensLicenseKey() {} // custom helper methods UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool IsKeyExpired() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool DoesKeyHaveFeature(const ELicenseFeature Feature); // methods directly out of the library UFUNCTION(BlueprintCallable, Category = "CryptolensUE") int32 get_product_id() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") int32 get_period() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") int64 get_created() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") int64 get_expires() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") int64 get_sign_date() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_block() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_trial_activation() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f1() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f2() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f3() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f4() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f5() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f6() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f7() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") bool get_f8() const; UFUNCTION(BlueprintCallable, Category = "CryptolensUE") FString ToString() const; cryptolens::optional<cryptolens::LicenseKey> GetLicenseKeyObj() const { return m_LicenseKey; } void Init(const FString& LicenseKey, Cryptolens& handle, cryptolens::Error& e); protected: private: // we really need C++17 support... cryptolens::optional<cryptolens::LicenseKey> m_LicenseKey; };
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/wincrypt.h
<filename>Source/ThirdParty/include/cryptolens/imports/windows/wincrypt.h<gh_stars>0 #include <wincrypt.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/openssl/rsa.h
<gh_stars>0 #include <openssl/rsa.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/openssl/bn.h
<reponame>trdwll/CryptolensUE #include <openssl/bn.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/winhttp.h
<gh_stars>0 #include <winhttp.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/iphlpapi.h
#include <iphlpapi.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/openssl/ssl.h
<reponame>trdwll/CryptolensUE #include <openssl/ssl.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/Wbemidl.h
#include <Wbemidl.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/curl/curl.h
<reponame>trdwll/CryptolensUE<filename>Source/ThirdParty/include/cryptolens/imports/curl/curl.h #include <curl/curl.h>
trdwll/CryptolensUE
Source/ThirdParty/include/cryptolens/imports/windows/comdef.h
<reponame>trdwll/CryptolensUE<filename>Source/ThirdParty/include/cryptolens/imports/windows/comdef.h<gh_stars>0 #include <comdef.h>
JoanKing/JKStatusBar
JKStatusBar/JKStatusBar/TestViewController.h
// // TestViewController.h // JKStatusBar // // Created by 王冲 on 2019/1/16. // Copyright © 2019年 JK科技有限公司. All rights reserved. // #import <UIKit/UIKit.h> NS_ASSUME_NONNULL_BEGIN @interface TestViewController : UIViewController @end NS_ASSUME_NONNULL_END
ArchLL/HGPersonalCenter
HGPersonalCenter/Tools/HGDeviceHelper.h
<filename>HGPersonalCenter/Tools/HGDeviceHelper.h<gh_stars>100-1000 // // HGDeviceHelper.h // HGPersonalCenter // // Created by Arch on 2018/9/17. // Copyright © 2019 <EMAIL>. All rights reserved. // #import <Foundation/Foundation.h> @interface HGDeviceHelper : NSObject + (BOOL)isIpad; + (BOOL)isExistFringe; + (BOOL)isExistJaw; + (CGFloat)safeAreaInsetsTop; + (CGFloat)safeAreaInsetsBottom; + (CGFloat)navigationBarHeight; + (CGFloat)topBarHeight; @end
ArchLL/HGPersonalCenter
HGPersonalCenter/Controllers/HGHomeViewController.h
// // HGHomeViewController.h // HGPersonalCenter // // Created by Arch on 2017/6/16. // Copyright © 2017年 mint_bin. All rights reserved. // #import <UIKit/UIKit.h> @interface HGHomeViewController : HGBaseViewController @end
ArchLL/HGPersonalCenter
HGPersonalCenter/Views/HGHeaderImageView.h
// // HGHeaderImageView.h // HGPersonalCenter // // Created by Arch on 2019/5/17. // Copyright © 2019 mint_bin. All rights reserved. // #import <UIKit/UIKit.h> @interface HGHeaderImageView : UIView @property (nonatomic) CGFloat initialHeight; @end
ArchLL/HGPersonalCenter
HGPersonalCenter/Controllers/BaseControllers/HGBaseViewController.h
<gh_stars>100-1000 // // HGBaseViewController.h // HGPersonalCenter // // Created by Arch on 2017/6/19. // Copyright © 2017年 mint_bin. All rights reserved. // #import <UIKit/UIKit.h> @interface HGBaseViewController : GKNavigationBarViewController @end
ArchLL/HGPersonalCenter
HGPersonalCenter/Controllers/HGMessageViewController.h
// // HGMessageViewController.h // HGPersonalCenter // // Created by Arch on 2019/5/15. // Copyright © 2019 <EMAIL>. All rights reserved. // #import <UIKit/UIKit.h> @interface HGMessageViewController : HGBaseViewController @end
ben-EDT/libatsc3
src/atsc3_mmt_signalling_message_types.c
/* * atsc3_mmt_signalling_messages_types.c * * Created on: Aug 10, 2019 * Author: jjustman */ #include "atsc3_mmt_signalling_message_types.h" int _MMT_SI_TYPES_ERROR_ENABLED = 1; int _MMT_SI_TYPES_WARN_ENABLED = 1; int _MMT_SI_TYPES_INFO_ENABLED = 1; int _MMT_SI_TYPES_DEBUG_ENABLED = 0; int _MMT_SI_TYPES_TRACE_ENABLED = 0; //jjustman-2021-07-07 - TODO: add all common A/331 MMT SI message types void mmt_atsc3_message_content_type_asset_header_free_asset_id(mmt_atsc3_message_content_type_asset_header_t* mmt_atsc3_message_content_type_asset_heaader) { if(mmt_atsc3_message_content_type_asset_heaader && mmt_atsc3_message_content_type_asset_heaader->asset_id) { freesafe((void*)mmt_atsc3_message_content_type_asset_heaader->asset_id); mmt_atsc3_message_content_type_asset_heaader->asset_id_length = 0; } } //MMT_ATSC3_MESSAGE_CONTENT_TYPE_VIDEO_STREAM_PROPERTIES_DESCRIPTOR ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_video_stream_properties_descriptor, mmt_atsc3_message_content_type_video_stream_properties_descriptor_asset); ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_video_stream_properties_descriptor); ATSC3_VECTOR_BUILDER_METHODS_PARENT_IMPLEMENTATION(mmt_atsc3_message_content_type_video_stream_properties_descriptor); //jjustman-2021-09-13 - todo: ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_video_stream_properties_descriptor_asset); //MMT_ATSC3_MESSAGE_CONTENT_TYPE_CAPTION_ASSET_DESCRIPTOR ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_caption_asset_descriptor, mmt_atsc3_message_content_type_caption_asset_descriptor_asset); ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_caption_asset_descriptor_asset); ATSC3_VECTOR_BUILDER_METHODS_PARENT_IMPLEMENTATION(mmt_atsc3_message_content_type_caption_asset_descriptor); //MMT_ATSC3_MESSAGE_CONTENT_TYPE_AUDIO_STREAM_PROPERTIES_DESCRIPTOR ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation, mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language); //ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language); void mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_free(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_t** mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_p) { if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_p) { mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_t* mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language = *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_p; if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language) { //other interior members here if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language->language) { freesafe((void*)mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language->language); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language->language_length = 0; } freesafe(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language = NULL; } *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language_p = NULL; } } ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset, mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation); //ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation); void mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_free(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_t** mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_p) { if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_p) { mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_t* mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation = *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_p; if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation) { mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_free_mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_language(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation); //other interior members here if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation->label_data_byte) { freesafe((void*)mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation->label_data_byte); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation->label_length = 0; } freesafe(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation = NULL; } *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation_p = NULL; } } ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_audio_stream_properties_descriptor, mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset); ATSC3_VECTOR_BUILDER_METHODS_PARENT_IMPLEMENTATION(mmt_atsc3_message_content_type_audio_stream_properties_descriptor); //ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset); void mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_free(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_t** mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_p) { if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_p) { mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_t* mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset = *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_p; if(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset) { mmt_atsc3_message_content_type_asset_header_free_asset_id(&mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset->asset_header); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_free_mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_presentation(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset); //other interior members here freesafe(mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset); mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset = NULL; } *mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_p = NULL; } } //MMT_ATSC3_MESSAGE_CONTENT_TYPE_SECURITY_PROPERTIES_DESCRIPTOR_LAURL ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_si_security_properties_descriptor_system, mmt_si_security_properties_descriptor_kid); //jjustman-2021-06-08 - TODO - impl for any uint8_t* refs for cleanup ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_si_security_properties_descriptor_kid); ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_si_security_properties_descriptor, mmt_si_security_properties_descriptor_system); //jjustman-2021-06-08 - TODO - impl for any uint8_t* refs for cleanup ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_si_security_properties_descriptor_system); ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_security_properties_descriptor_LAURL_asset, mmt_atsc3_message_content_type_security_properties_descriptor_LAURL_asset_license_info) //jjustman-2021-06-08 - TODO - impl for any uint8_t* refs for cleanup ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_security_properties_descriptor_LAURL_asset_license_info); ATSC3_VECTOR_BUILDER_METHODS_PARENT_IMPLEMENTATION(mmt_atsc3_message_content_type_security_properties_descriptor_LAURL); ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(mmt_atsc3_message_content_type_security_properties_descriptor_LAURL, mmt_atsc3_message_content_type_security_properties_descriptor_LAURL_asset) //jjustman-2021-06-08 - TODO - impl for any uint8_t* refs for cleanup ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(mmt_atsc3_message_content_type_security_properties_descriptor_LAURL_asset); //jjustman-2021-07-26 - TODO: add additional cleanup for MMT_ATSC3 message type processing (e.g. >= 0x8100) and internal mp_* ISO23008-1 types void mmt_signalling_message_header_and_payload_free(mmt_signalling_message_header_and_payload_t** mmt_signalling_message_header_and_payload_p) { mmt_signalling_message_header_and_payload_t* mmt_signalling_message_header_and_payload = *mmt_signalling_message_header_and_payload_p; __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: %p: message_id: %d, message type: %d", mmt_signalling_message_header_and_payload, mmt_signalling_message_header_and_payload->message_header.message_id, mmt_signalling_message_header_and_payload->message_header.MESSAGE_id_type); if(mmt_signalling_message_header_and_payload) { __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: clearing MMT_ATSC3_MESSAGE_ID"); //determine if we have any internal mallocs to clear if(mmt_signalling_message_header_and_payload->message_header.MESSAGE_id_type >= MMT_ATSC3_MESSAGE_ID) { //free structs from mmt_atsc3_message_payload_t __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.URI_payload ptr: %p", mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.URI_payload); if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.URI_payload) { free(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.URI_payload); mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.URI_payload = NULL; } __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content ptr: %p", mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content); if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content) { free(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content); mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content = NULL; } if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_blockt) { block_Destroy(&mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_blockt); } __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_compressed ptr: %p", mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_compressed); if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_compressed) { free(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_compressed); mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.atsc3_message_content_compressed = NULL; } //mmt_atsc3_signalling_information_usbd_component_free if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_signalling_information_usbd_component) { mmt_atsc3_signalling_information_usbd_component_free(&mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_signalling_information_usbd_component); } //mmt_atsc3_route_component if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_route_component) { if(!mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_route_component->__is_pinned_to_context) { mmt_atsc3_route_component_free(&mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_route_component); } } //mmt_atsc3_held_message if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_held_message) { mmt_atsc3_held_message_free(&mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_held_message); } //mmt_atsc3_message_content_type_caption_asset_descriptor if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_caption_asset_descriptor) { //mmt_atsc3_message_content_type_caption_asset_descriptor_free(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_caption_asset_descriptor); freesafe((void*)mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_caption_asset_descriptor); } //mmt_atsc3_message_content_type_audio_stream_properties_descriptor if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_audio_stream_properties_descriptor) { mmt_atsc3_message_content_type_audio_stream_properties_descriptor_free_mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_audio_stream_properties_descriptor); freesafe((void*)mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_audio_stream_properties_descriptor); } // //mmt_atsc3_message_content_type_video_properties_descriptor // if(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_audio_stream_properties_descriptor) { // mmt_atsc3_message_content_type_audio_stream_properties_descriptor_asset_free(mmt_signalling_message_header_and_payload->message_payload.mmt_atsc3_message_payload.mmt_atsc3_message_content_type_video_properties_descriptor); // } } else if(mmt_signalling_message_header_and_payload->message_header.MESSAGE_id_type == MPT_message) { //clear out mp_table __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: clearing mp_table: assets: %d", mmt_signalling_message_header_and_payload->message_payload.mp_table.number_of_assets); for(int i=0; i < mmt_signalling_message_header_and_payload->message_payload.mp_table.number_of_assets; i++) { mp_table_asset_row_t* mp_table_asset_row = &mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_asset_row[i]; __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free_inner: i: %d, ptr: %p", i, mp_table_asset_row); atsc3_mmt_mp_table_asset_row_free_inner(mp_table_asset_row); } //since mp_table_asset_row is allocated as calloc(numAssets, sizeof(mp_table_asset_row_t)), we can only do one free() free(mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_asset_row); mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_asset_row = NULL; __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id: %p", mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id); if(mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id) { free(mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id); mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id = NULL; mmt_signalling_message_header_and_payload->message_payload.mp_table.mmt_package_id.mmt_package_id_length = 0; } if(mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_descriptors.mp_table_descriptors_byte) { free(mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_descriptors.mp_table_descriptors_byte); mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_descriptors.mp_table_descriptors_byte = NULL; mmt_signalling_message_header_and_payload->message_payload.mp_table.mp_table_descriptors.mp_table_descriptors_length = 0; } } else { __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: clearing mp_table: assets: %d", mmt_signalling_message_header_and_payload->message_payload.mp_table.number_of_assets); } free(mmt_signalling_message_header_and_payload); *mmt_signalling_message_header_and_payload_p = NULL; } } mp_table_asset_row_t* atsc3_mmt_mp_table_asset_row_duplicate(const mp_table_asset_row_t* mp_table_asset_row_src) { mp_table_asset_row_t* mp_table_asset_row_dst = calloc(1, sizeof(mp_table_asset_row_t)); //hack to get our non-ptr fields duplicated memcpy(mp_table_asset_row_dst, mp_table_asset_row_src, sizeof(mp_table_asset_row_t)); if (mp_table_asset_row_src->identifier_mapping.identifier_type == 0x00) { //asset_id type if(mp_table_asset_row_src->identifier_mapping.asset_id.asset_id_length && mp_table_asset_row_src->identifier_mapping.asset_id.asset_id) { mp_table_asset_row_dst->identifier_mapping.asset_id.asset_id = calloc(mp_table_asset_row_src->identifier_mapping.asset_id.asset_id_length, sizeof(uint8_t)); memcpy(mp_table_asset_row_dst->identifier_mapping.asset_id.asset_id, mp_table_asset_row_src->identifier_mapping.asset_id.asset_id, mp_table_asset_row_src->identifier_mapping.asset_id.asset_id_length); } else { mp_table_asset_row_dst->identifier_mapping.asset_id.asset_id_length = 0; mp_table_asset_row_dst->identifier_mapping.asset_id.asset_id = NULL; } } else if(mp_table_asset_row_src->identifier_mapping.identifier_type == 0x01) { //url if(mp_table_asset_row_src->identifier_mapping.url_count && mp_table_asset_row_src->identifier_mapping.url_length_list) { mp_table_asset_row_dst->identifier_mapping.url_length_list = calloc(mp_table_asset_row_src->identifier_mapping.url_count, sizeof(url_length_t)); for(int i=0; i < mp_table_asset_row_src->identifier_mapping.url_count; i++) { url_length_t* url_length_old = &mp_table_asset_row_src->identifier_mapping.url_length_list[i]; url_length_t* url_length_new = &mp_table_asset_row_dst->identifier_mapping.url_length_list[i]; url_length_new->length = url_length_old->length; url_length_new->byte = calloc(url_length_new->length, sizeof(uint8_t)); memcpy(url_length_new->byte, url_length_old->byte, url_length_new->length); } } else { mp_table_asset_row_dst->identifier_mapping.url_count = 0; mp_table_asset_row_dst->identifier_mapping.url_length_list = NULL; } } else if(mp_table_asset_row_src->identifier_mapping.identifier_type == 0x02) { //regex if(mp_table_asset_row_src->identifier_mapping.regex_length && mp_table_asset_row_src->identifier_mapping.regex_byte) { mp_table_asset_row_dst->identifier_mapping.regex_byte = calloc(mp_table_asset_row_src->identifier_mapping.regex_length, sizeof(uint8_t)); memcpy(mp_table_asset_row_dst->identifier_mapping.regex_byte, mp_table_asset_row_src->identifier_mapping.regex_byte, mp_table_asset_row_src->identifier_mapping.regex_length); } } else if(mp_table_asset_row_src->identifier_mapping.identifier_type == 0x03) { //representation_id if(mp_table_asset_row_src->identifier_mapping.representation_id_length && mp_table_asset_row_src->identifier_mapping.representation_id_byte) { mp_table_asset_row_dst->identifier_mapping.representation_id_byte = calloc(mp_table_asset_row_src->identifier_mapping.representation_id_length, sizeof(uint8_t)); memcpy(mp_table_asset_row_dst->identifier_mapping.representation_id_byte, mp_table_asset_row_src->identifier_mapping.representation_id_byte, mp_table_asset_row_src->identifier_mapping.representation_id_length); } } else { //any other, private if (mp_table_asset_row_src->identifier_mapping.private_length && mp_table_asset_row_src->identifier_mapping.private_byte) { mp_table_asset_row_dst->identifier_mapping.private_byte = calloc(mp_table_asset_row_src->identifier_mapping.private_length, sizeof(uint8_t)); memcpy(mp_table_asset_row_dst->identifier_mapping.private_byte, mp_table_asset_row_src->identifier_mapping.private_byte, mp_table_asset_row_src->identifier_mapping.private_length); } } if(mp_table_asset_row_src->asset_descriptors_length && mp_table_asset_row_src->asset_descriptors_payload) { mp_table_asset_row_dst->asset_descriptors_payload = calloc(mp_table_asset_row_src->asset_descriptors_length, sizeof(uint8_t)); memcpy(mp_table_asset_row_dst->asset_descriptors_payload, mp_table_asset_row_src->asset_descriptors_payload, mp_table_asset_row_src->asset_descriptors_length); } else { mp_table_asset_row_dst->asset_descriptors_length = 0; mp_table_asset_row_dst->asset_descriptors_payload = NULL; } if(mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor) { mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor = calloc(1, sizeof(mmt_signalling_message_mpu_timestamp_descriptor_t)); mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->descriptor_tag = mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->descriptor_tag; mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->descriptor_length = mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->descriptor_length; mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n = mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n; if(mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n && mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple) { mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple = calloc(mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n, sizeof(mmt_signalling_message_mpu_tuple_t)); for(int i=0; i < mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n; i++) { mmt_signalling_message_mpu_tuple_t* mmt_signalling_message_mpu_tuple_src = &mp_table_asset_row_src->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple[i]; mmt_signalling_message_mpu_tuple_t* mmt_signalling_message_mpu_tuple_dst = &mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple[i]; mmt_signalling_message_mpu_tuple_dst->mpu_sequence_number = mmt_signalling_message_mpu_tuple_src->mpu_sequence_number; mmt_signalling_message_mpu_tuple_dst->mpu_presentation_time = mmt_signalling_message_mpu_tuple_src->mpu_presentation_time; } } else { mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple_n = 0; mp_table_asset_row_dst->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple = NULL; } } return mp_table_asset_row_dst; } /* * jjustman-2020-12-02 - since mp_table_asset_row is allocated as calloc(numAssets, sizeof(mp_table_asset_row_t)), we can only do one free() */ void atsc3_mmt_mp_table_asset_row_free_inner(mp_table_asset_row_t* mp_table_asset_row) { if (mp_table_asset_row) { if (mp_table_asset_row->identifier_mapping.identifier_type == 0x00) { if (mp_table_asset_row->identifier_mapping.asset_id.asset_id) { //mp_table_asset_row->identifier_mapping.asset_id.asset_id_length mp_table_asset_row->identifier_mapping.asset_id.asset_id_length = 0; free(mp_table_asset_row->identifier_mapping.asset_id.asset_id); mp_table_asset_row->identifier_mapping.asset_id.asset_id = NULL; } } else { __MMT_SI_TYPES_WARN("atsc3_mmt_mp_table_asset_row_free: TODO: cleanup mp_table_asset_row->identifier_mapping.identifier_type: 0x%02x instance", mp_table_asset_row->identifier_mapping.identifier_type); } __MMT_SI_TYPES_DEBUG("mmt_signalling_message_header_and_payload_free: mmt_signalling_message_mpu_timestamp_descriptor: %p", mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor); if (mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor) { if (mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple) { free(mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple); mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor->mpu_tuple = NULL; } free(mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor); mp_table_asset_row->mmt_signalling_message_mpu_timestamp_descriptor = NULL; } if (mp_table_asset_row->asset_descriptors_payload) { //mp_table_asset_row->asset_descriptors_length? mp_table_asset_row->asset_descriptors_length = 0; free(mp_table_asset_row->asset_descriptors_payload); mp_table_asset_row->asset_descriptors_payload = NULL; } } } void mmt_atsc3_signalling_information_usbd_component_free(mmt_atsc3_signalling_information_usbd_component_t** mmt_atsc3_signalling_information_usbd_component_p) { if(mmt_atsc3_signalling_information_usbd_component_p) { mmt_atsc3_signalling_information_usbd_component_t* mmt_atsc3_signalling_information_usbd_component = *mmt_atsc3_signalling_information_usbd_component_p; if(mmt_atsc3_signalling_information_usbd_component) { if(mmt_atsc3_signalling_information_usbd_component->usbd_payload) { block_Destroy(&mmt_atsc3_signalling_information_usbd_component->usbd_payload); } free(mmt_atsc3_signalling_information_usbd_component); mmt_atsc3_signalling_information_usbd_component = NULL; } *mmt_atsc3_signalling_information_usbd_component_p = NULL; } } void mmt_atsc3_route_component_free(mmt_atsc3_route_component_t** mmt_atsc3_route_component_p) { if(mmt_atsc3_route_component_p) { mmt_atsc3_route_component_t* mmt_atsc3_route_component = *mmt_atsc3_route_component_p; if(mmt_atsc3_route_component) { if(mmt_atsc3_route_component->stsid_uri_s) { freeclean((void**)&mmt_atsc3_route_component->stsid_uri_s); } if(mmt_atsc3_route_component->stsid_destination_ip_address_s) { freeclean((void**)&mmt_atsc3_route_component->stsid_destination_ip_address_s); } if(mmt_atsc3_route_component->stsid_source_ip_address_s) { freeclean((void**)&mmt_atsc3_route_component->stsid_source_ip_address_s); } free(mmt_atsc3_route_component); mmt_atsc3_route_component = NULL; } *mmt_atsc3_route_component_p = NULL; } } void mmt_atsc3_held_message_free(mmt_atsc3_held_message_t** mmt_atsc3_held_message_p) { if(mmt_atsc3_held_message_p) { mmt_atsc3_held_message_t* mmt_atsc3_held_message = *mmt_atsc3_held_message_p; if(mmt_atsc3_held_message) { if(mmt_atsc3_held_message->held_message) { block_Destroy(&mmt_atsc3_held_message->held_message); } free(mmt_atsc3_held_message); mmt_atsc3_held_message = NULL; } *mmt_atsc3_held_message_p = NULL; } }
ben-EDT/libatsc3
src/atsc3_route_object.c
<gh_stars>10-100 /* * atsc3_route_object.c * * Created on: Jul 27, 2020 * Author: jjustman * * * <EMAIL> tools % tail -f debug.log.5003| grep "atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received\|atsc3_route_object_is_complete: true" atsc3_route_object.c : 153:DEBUG:1595953002.4722:atsc3_route_object_is_complete: true, complete, with tsi: 1060, toi: 3, atsc3_route_object_lct_packet_received_v: 1, last_object_position: 780, atsc3_route_object->object_length: 780 atsc3_route_object.c : 166:DEBUG:1595953002.4724:atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: atsc3_route_object: 0x7fc740004db0, tsi: 1060, toi: 3, clearing 1 route_object_lct_packet_received entries atsc3_route_object.c : 153:DEBUG:1595953002.6641:atsc3_route_object_is_complete: true, complete, with tsi: 1060, toi: 3, atsc3_route_object_lct_packet_received_v: 1, last_object_position: 780, atsc3_route_object->object_length: 780 atsc3_route_object.c : 166:DEBUG:1595953002.6642:atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: atsc3_route_object: 0x7fc740004db0, tsi: 1060, toi: 3, clearing 1 route_object_lct_packet_received entries * */ #include "atsc3_route_object.h" ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(atsc3_route_object, atsc3_route_object_lct_packet_received); int _ROUTE_OBJECT_INFO_ENABLED = 0; int _ROUTE_OBJECT_DEBUG_ENABLED = 0; int _ROUTE_OBJECT_TRACE_ENABLED = 0; int atsc3_route_object_lct_packet_received_cmp_fn(const struct avltree_node *a, const struct avltree_node *b) { atsc3_route_object_lct_packet_received_node_t *p = avltree_container_of(a, atsc3_route_object_lct_packet_received_node_t, node); atsc3_route_object_lct_packet_received_node_t *q = avltree_container_of(b, atsc3_route_object_lct_packet_received_node_t, node); return (p->key < q->key)? -1 : (p->key > q->key) ? 1 : 0 ; } atsc3_route_object_t* atsc3_route_object_new() { atsc3_route_object_t* atsc3_route_object = calloc(1, sizeof(atsc3_route_object_t)); avltree_init(&atsc3_route_object->atsc3_route_object_lct_packet_received_tree, atsc3_route_object_lct_packet_received_cmp_fn, 0); atsc3_route_object->recovery_file_buffer_position = -1; return atsc3_route_object; } /* * jjustman-2020-12-23 - be VERY careful about making sure to also remove any dangling references to this route_object in the lls_sls_alc_monitor, for faster carousel recovery for corrupted payloads, ala: * * e.g. atsc3_alc_utils.c:atsc3_alc_packet_persist_to_toi_resource_process_sls_mbms_and_emit_callback * * if((matching_sls_alc_flow = atsc3_sls_alc_flow_find_entry_tsi(&lls_sls_alc_monitor->atsc3_sls_alc_all_s_tsid_flow_v, alc_packet->def_lct_hdr->tsi))) { atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_sls_alc_flow_remove_atsc3_route_object(matching_sls_alc_flow, atsc3_route_object); atsc3_route_object_free(&atsc3_route_object); } as by default atsc3_lls_types.c: atsc3_lls_sls_alc_monitor_check_all_s_tsid_flows_has_given_up_route_objects will handle invocation and freeing of this atsc3_route_object after local expiry */ void atsc3_route_object_free(atsc3_route_object_t** atsc3_route_object_p) { if(atsc3_route_object_p) { atsc3_route_object_t* atsc3_route_object = *atsc3_route_object_p; if(atsc3_route_object) { _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_free: p: %p, tsi: %d, toi: %d, before closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d), final_object_recovery_filename_for_logging: %s", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size, atsc3_route_object->final_object_recovery_filename_for_logging ); freeclean((void**)&atsc3_route_object->temporary_object_recovery_filename); freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_eviction); freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_logging); //most important to clear the lct packets recv atsc3_route_object_recovery_file_handle_flush_and_close(atsc3_route_object); //jjustman-2020-08-04 - important, always call these two together.. atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_free: p: %p, tsi: %d, toi: %d, after closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d)", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size ); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; free(atsc3_route_object); atsc3_route_object = NULL; } *atsc3_route_object_p = NULL; } } void atsc3_route_object_lct_packet_received_free(atsc3_route_object_lct_packet_received_t** atsc3_route_object_lct_packet_received_p) { if(atsc3_route_object_lct_packet_received_p) { atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received = *atsc3_route_object_lct_packet_received_p; if(atsc3_route_object_lct_packet_received) { if(atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist) { block_Destroy(&atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); } free(atsc3_route_object_lct_packet_received); atsc3_route_object_lct_packet_received = NULL; } *atsc3_route_object_lct_packet_received_p = NULL; } } void atsc3_route_object_add_atsc3_route_object_lct_packet_len(atsc3_route_object_t* atsc3_route_object, atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received) { atsc3_route_object->cumulative_lct_packet_len += atsc3_route_object_lct_packet_received->packet_len; } void atsc3_route_object_set_is_toi_init_object(atsc3_route_object_t* atsc3_route_object, bool is_toi_init) { atsc3_route_object->is_toi_init = is_toi_init; } void atsc3_route_object_set_temporary_object_recovery_filename_if_null(atsc3_route_object_t* atsc3_route_object, char* temporary_filename) { if(!atsc3_route_object->temporary_object_recovery_filename) { atsc3_route_object->temporary_object_recovery_filename = strdup(temporary_filename); } } char* atsc3_route_object_get_temporary_object_recovery_filename_strdup(atsc3_route_object_t* atsc3_route_object) { char* temporary_filename = NULL; if(atsc3_route_object->temporary_object_recovery_filename) { temporary_filename = strdup(atsc3_route_object->temporary_object_recovery_filename); } return temporary_filename; } void atsc3_route_object_clear_temporary_object_recovery_filename(atsc3_route_object_t* atsc3_route_object) { freeclean((void**)&atsc3_route_object->temporary_object_recovery_filename); } void atsc3_route_object_set_final_object_recovery_filename_for_eviction(atsc3_route_object_t* atsc3_route_object, char* final_object_recovery_filename_for_eviction) { freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_eviction); atsc3_route_object->final_object_recovery_filename_for_eviction = strdup(final_object_recovery_filename_for_eviction); } void atsc3_route_object_set_final_object_recovery_filename_for_logging(atsc3_route_object_t* atsc3_route_object, char* final_object_recovery_filename_for_logging) { freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_logging); atsc3_route_object->final_object_recovery_filename_for_logging = strdup(final_object_recovery_filename_for_logging); } bool atsc3_route_object_lct_packet_received_promote_atsc3_alc_packet_alc_payload_to_pending_block(atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received, atsc3_alc_packet_t* alc_packet) { if(!atsc3_route_object_lct_packet_received || !alc_packet || !alc_packet->alc_payload || !alc_packet->alc_len) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_lct_packet_received_promote_atsc3_alc_packet_alc_payload_to_pending_block: can't create pending_alc_payload_to_persist, atsc3_route_object_lct_packet_received: %p, alc_packet: %p", atsc3_route_object_lct_packet_received, alc_packet); return false; } if(atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_lct_packet_received_promote_atsc3_alc_packet_alc_payload_to_pending_block: pre-existing pending_alc_payload_to_persist, destroying block_t, atsc3_route_object_lct_packet_received: %p, pending_alc_payload_to_persist: %p, size: %d", atsc3_route_object_lct_packet_received, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist->p_size); block_Destroy(&atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); } atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist = block_Duplicate_from_ptr(alc_packet->alc_payload, alc_packet->alc_len); return true; } // //bool atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position(atsc3_route_object_t* atsc3_route_object, atsc3_alc_packet_t* alc_packet) { // if(!atsc3_route_object) { // return false; // } // // if(alc_packet->use_sbn_esi) { // //jjustman-2020-08-05: TODO - for raptorQ fec - atsc3_route_object_repair_symbol_add(...) for this alc_packet // //bail // return false; // } else if(alc_packet->use_start_offset) { // if(atsc3_route_object->recovery_file_buffer_position == -1 || !atsc3_route_object->recovery_file_buffer) { // // //we have to force-destroy this in-flight block // //jjustman-2020-08-05 - log this // if(atsc3_route_object->recovery_file_buffer) { // block_Destroy(&atsc3_route_object->recovery_file_buffer); // } // // //borrowed from atsc3_route_object_set_object_recovery_complete // atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); // atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; // atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); // atsc3_route_object->cumulative_lct_packet_len = 0; // atsc3_route_object->recovery_file_buffer_position = -1; // // if(!atsc3_route_object->object_length) { // //bail early // return false; // } // // uint32_t recovery_file_buffer_chunk_position = (alc_packet->start_offset / __ATSC3_ROUTE_OBJECT_PERSIST_BLOCK_SIZE_BYTES__) * __ATSC3_ROUTE_OBJECT_PERSIST_BLOCK_SIZE_BYTES__; // atsc3_route_object->recovery_file_buffer = recovery_file_buffer_chunk_position; // // uint32_t block_size_to_alloc = __MIN(__ATSC3_ROUTE_OBJECT_PERSIST_BLOCK_SIZE_BYTES__, atsc3_route_object->object_length - alc_packet->start_offset); // return false; // } // //otherwise, we should have // return true; // } else { // _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_route_object: %p, tsi: %d, toi: %d, alc_packet: %p is not use_sbn_esi AND not use_start_offset?!", // atsc3_route_object, // atsc3_route_object->tsi, // atsc3_route_object->toi, // alc_packet); // // return false; // } //} // // ///* // * // * jjustman-2020-08-05 - chunked flushing of contigious atsc3_route_object_lct_packet_received block_t* // * merge and block_write to temporary_object_recovery filename rather than large block_alloc and fseek/fwrite for every lct packet // * // * TODO: buffer up to __ATSC3_ROUTE_OBJECT_PERSIST_BLOCK_SIZE_BYTES__ of block_t before flushing, avoiding most small pre_allocation for small objects // * // * object is then flushed and closed to disk with atsc3_route_object_recovery_file_handle_flush_and_close // * // * // * first pass: only dump our full payload to disk if we are logically "complete" // */ // //int atsc3_route_object_persist_recovery_block_from_lct_packet_vector(atsc3_route_object_t* atsc3_route_object) { // int bytesWritten = 0; // char* temporary_recovery_filename = NULL; // bool is_source_symbol = false; // // if(!atsc3_route_object || !atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received) { // _ATSC3_SLS_ALC_FLOW_WARN("atsc3_route_object_persist_atsc3_alc_packet_from_udp_flow: atsc3_route_object: %p, most_recent_atsc3_route_object_lct_packet_received is NULL, discarding!", atsc3_route_object); // return -2; // } // // // // is_source_symbol = atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position(atsc3_route_object, alc_packet); // // //if we are a repair symbol, skip source symbol recovery and defer processing for raptorQ // if(!is_source_symbol) { // return 0; // } // // int32_t block_remaining_size = block_Remaining_size(atsc3_route_object->recovery_file_buffer); // // //compute gap between atsc3_route_object->recovery_file_buffer_position and our start_offset // int32_t relative_buffer_write_position = alc_packet->start_offset - atsc3_route_object->recovery_file_buffer_position; // int32_t updated_file_buffer_position_after_write = alc_packet->start_offset + alc_packet->alc_len; // int32_t required_buffer_size = updated_file_buffer_position_after_write - atsc3_route_object->recovery_file_buffer_position; // // if(relative_buffer_write_position >= 0) { //this is an "append" // // if(block_remaining_size >= required_buffer_size) { //if we have enough space, write to our block_t // block_Seek(atsc3_route_object->recovery_file_buffer, relative_buffer_write_position); // block_Write(atsc3_route_object->recovery_file_buffer, alc_packet->alc_payload, alc_packet->alc_len); // //note: only set atsc3_route_object->recovery_file_buffer_position) after we have flushed out to disk // // _ATSC3_SLS_ALC_FLOW_INFO("atsc3_route_object_persist_atsc3_alc_packet_from_udp_flow: calling block_Write with alc_packet, tsi: %d, toi: %d, start_offset: %d, len: %d, remaining recovery_file_buffer size: %d, atsc3_route_object->recovery_file_buffer_position: %d", // alc_packet->def_lct_hdr->tsi, // alc_packet->def_lct_hdr->toi, // alc_packet->start_offset, // alc_packet->alc_len, // block_Remaining_size(atsc3_route_object->recovery_file_buffer), // atsc3_route_object->recovery_file_buffer_position); // // // } else { // //otherwise flush out disk and create new recovery_file_buffer and write our alc_packet // _ATSC3_SLS_ALC_FLOW_INFO("atsc3_route_object_persist_atsc3_alc_packet_from_udp_flow: flushing and reallocing recovery_file_buffer, tsi: %d, toi: %d, start_offset: %d, len: %d, remaining recovery_file_buffer size: %d, required_buffer_size size: %d, alc_len: %d", // alc_packet->def_lct_hdr->tsi, // alc_packet->def_lct_hdr->toi, // alc_packet->start_offset, // alc_packet->alc_len, // block_Remaining_size(atsc3_route_object->recovery_file_buffer), // required_buffer_size, // alc_packet->alc_len); // // bytesWritten = atsc3_route_object_recovery_file_buffer_flush_block_to_temporary_object_recovery_filename(atsc3_route_object); // atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position(atsc3_route_object, alc_packet); // block_Write(atsc3_route_object->recovery_file_buffer, alc_packet->alc_payload, alc_packet->alc_len); // atsc3_route_object->recovery_file_buffer_position = updated_file_buffer_position_after_write; // // } // } else if(relative_buffer_write_position < 0) { // //we might have a carousel packet, but cheat for our flush to disk // _ATSC3_SLS_ALC_FLOW_INFO("atsc3_route_object_persist_atsc3_alc_packet_from_udp_flow: buffer_gap_size < 0! flushing and reallocing recovery_file_buffer, tsi: %d, toi: %d, start_offset: %d, len: %d, remaining recovery_file_buffer size: %d, relative_buffer_write_position: %d, alc_len: %d", // alc_packet->def_lct_hdr->tsi, // alc_packet->def_lct_hdr->toi, // alc_packet->start_offset, // alc_packet->alc_len, // block_Remaining_size(atsc3_route_object->recovery_file_buffer), // relative_buffer_write_position, // alc_packet->alc_len); // // bytesWritten = atsc3_route_object_recovery_file_buffer_flush_block_to_temporary_object_recovery_filename(atsc3_route_object); // //hack...! let fseek do the hard work // atsc3_route_object->recovery_file_buffer = block_Duplicate_from_ptr(alc_packet->alc_payload, alc_packet->alc_len); // atsc3_route_object->recovery_file_buffer_position = alc_packet->start_offset; // bytesWritten = atsc3_route_object_recovery_file_buffer_flush_block_to_temporary_object_recovery_filename(atsc3_route_object); // } // // return bytesWritten; //} //REQUIRED: must have previously called atsc3_route_object_is_complete() to invoked qsort against // qsort((void**)atsc3_route_object->atsc3_route_object_lct_packet_received_v.data, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, sizeof(atsc3_route_object_lct_packet_received_t**), atsc3_route_object_lct_packet_received_generic_sbn_start_offset_comparator); int atsc3_route_object_persist_recovery_buffer_all_pending_lct_packet_vector(atsc3_route_object_t* atsc3_route_object) { int recovery_rebuilt_payload_size = 0; atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received = NULL; if(atsc3_route_object->recovery_file_buffer) { block_Destroy(&atsc3_route_object->recovery_file_buffer); } if(!atsc3_route_object->object_length) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_persist_recovery_buffer_all_pending_lct_packet_vector: atsc3_route_object: %p, object_length is invalid: %d", atsc3_route_object, atsc3_route_object->object_length); return -1; } atsc3_route_object->recovery_file_buffer = block_Alloc(atsc3_route_object->object_length); atsc3_route_object->recovery_file_buffer_position = 0; //TODO: check to make sure that our atsc3_route_objec passed atsc3_route_object_is_complete() //step 1 - rebuild our atsc3_route_object->recovery_file_buffer for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; if(atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist) { if(atsc3_route_object_lct_packet_received->use_start_offset) { block_Seek(atsc3_route_object->recovery_file_buffer, atsc3_route_object_lct_packet_received->start_offset); block_AppendFull(atsc3_route_object->recovery_file_buffer, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); recovery_rebuilt_payload_size += atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist->p_size; } else { //jjustman-2021-02-03 - add support for (optional sbn)^esi for codepoint==128, otherwise, TBD if(atsc3_route_object_lct_packet_received->codepoint == 128) { block_Seek(atsc3_route_object->recovery_file_buffer, atsc3_route_object_lct_packet_received->esi); block_AppendFull(atsc3_route_object->recovery_file_buffer, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); recovery_rebuilt_payload_size += atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist->p_size; } else { _ATSC3_ROUTE_OBJECT_ERROR("atsc3_route_object_persist_recovery_buffer_all_pending_lct_packet_vector: i: %d, codepoint: %d, atsc3_route_object_lct_packet_received: %p, ERROR: use_start_offset: %d, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist: %p", i, atsc3_route_object_lct_packet_received->codepoint, atsc3_route_object_lct_packet_received, atsc3_route_object_lct_packet_received->use_start_offset, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); } } } else { _ATSC3_ROUTE_OBJECT_ERROR("atsc3_route_object_persist_recovery_buffer_all_pending_lct_packet_vector: i: %d, atsc3_route_object_lct_packet_received: %p, ERROR: use_start_offset: %d, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist: %p", i, atsc3_route_object_lct_packet_received, atsc3_route_object_lct_packet_received->use_start_offset, atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); } } //step 2 - free our atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist entries for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; if(atsc3_route_object_lct_packet_received->use_start_offset && atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist) { block_Destroy(&atsc3_route_object_lct_packet_received->pending_alc_payload_to_persist); } } return recovery_rebuilt_payload_size; } int64_t atsc3_route_object_recovery_file_buffer_flush_block_to_temporary_object_recovery_filename(atsc3_route_object_t* atsc3_route_object) { int64_t bytes_written = 0; int res = 0; FILE* fp = NULL; if(!atsc3_route_object || !atsc3_route_object->recovery_file_buffer || !atsc3_route_object->recovery_file_buffer->p_buffer || !atsc3_route_object->recovery_file_buffer->p_size) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_route_object: %p, recovery_file_buffer is invalid!", atsc3_route_object); bytes_written = -4; goto free_recovery_file_buffer; } if(!atsc3_route_object->temporary_object_recovery_filename || atsc3_route_object->recovery_file_buffer_position < 0) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_route_object: %p, temporary_object_recovery_filename is NULL!, recovery_file_buffer_position is: %lld", atsc3_route_object, atsc3_route_object->recovery_file_buffer_position); bytes_written = -3; goto free_recovery_file_buffer; } if(atsc3_route_object->recovery_file_handle) { int res = 0; //try a sanity check for seeking to 0 res = fseek(atsc3_route_object->recovery_file_handle, 0, SEEK_SET); if(!res) { fp = atsc3_route_object->recovery_file_handle; } else { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_route_object: %p, atsc3_route_object->recovery_file_handle: %p, fseek to (0, SEEK_SET) returned error: %d", atsc3_route_object, atsc3_route_object->recovery_file_handle, res); fclose(atsc3_route_object->recovery_file_handle); atsc3_route_object->recovery_file_handle = NULL; } } if(!fp) { //make sure we have our dump output path struct stat st = {0}; if(stat(__ALC_DUMP_OUTPUT_PATH__, &st) == -1) { mkdir(__ALC_DUMP_OUTPUT_PATH__, 0777); } fp = atsc3_object_open(atsc3_route_object->temporary_object_recovery_filename); if(!fp) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_alc_object_open:: atsc3_route_object: %p, atsc3_route_object->temporary_object_recovery_filename: %s failed", atsc3_route_object, atsc3_route_object->temporary_object_recovery_filename); bytes_written = -2; goto free_recovery_file_buffer; } else { atsc3_route_object->recovery_file_handle = fp; } } res = fseek(fp, atsc3_route_object->recovery_file_buffer_position, SEEK_SET); if(!res) { res = fwrite(atsc3_route_object->recovery_file_buffer->p_buffer, atsc3_route_object->recovery_file_buffer->p_size, 1, fp); if(res != 1) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_buffer_ensure_alloc_and_position: atsc3_route_object: %p, atsc3_route_object->recovery_file_handle: %p, fwrite of %d bytes failed from block_t: %p - res: %d", atsc3_route_object, atsc3_route_object->recovery_file_handle, atsc3_route_object->recovery_file_buffer->p_size, atsc3_route_object->recovery_file_buffer->p_buffer, res); fclose(fp); fp = NULL; atsc3_route_object->recovery_file_handle = NULL; bytes_written = -1; goto free_recovery_file_buffer; } else { atsc3_route_object->recovery_file_buffer_position = (uint32_t) ftell(fp); bytes_written = atsc3_route_object->recovery_file_buffer->p_size; block_Destroy(&atsc3_route_object->recovery_file_buffer); goto done; } } free_recovery_file_buffer: if(atsc3_route_object->recovery_file_buffer) { block_Destroy(&atsc3_route_object->recovery_file_buffer); } //borrowed from atsc3_route_object_set_object_recovery_complete atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); atsc3_route_object->recovery_file_buffer_position = -1; //hack, if we wern't able to flush this buffer to disk, clear out our done: return bytes_written; } /* * method: atsc3_route_object_set_object_recovery_complete * * used to mark this atsc3_route_object as fully recovered and persisted on disk * * only run this when you are done working with atsc3_route_object_lct_packets, * will release internal LCT packet container/counts * * invoked: atsc3_alc_persist_route_object_lct_packet_received_for_lls_sls_alc_monitor_all_flows * * borrowed from atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received */ void atsc3_route_object_set_object_recovery_complete(atsc3_route_object_t* atsc3_route_object) { atsc3_route_object->recovery_complete_timestamp = gtl(); // _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_set_object_recovery_complete: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d, timestamp: %.2lu", // atsc3_route_object, // atsc3_route_object->tsi, // atsc3_route_object->toi, // atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, // atsc3_route_object->recovery_complete_timestamp); //this will be invoked from atsc3_lls_sls_alc_monitor_check_all_s_tsid_flows_has_given_up_route_objects //atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received(atsc3_route_object); //borrowed from atsc3_route_object_free _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_set_object_recovery_complete: p: %p, tsi: %d, toi: %d, before closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d)", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size ); atsc3_route_object_recovery_file_handle_flush_and_close(atsc3_route_object); //jjustman-2020-08-04 - important, always call these two together.. atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); //end borrowed from atsc3_route_object_free _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_set_object_recovery_complete: p: %p, tsi: %d, toi: %d, after closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d)", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size ); } void atsc3_route_object_recovery_file_handle_assign(atsc3_route_object_t* atsc3_route_object, FILE* recovery_file_handle) { if(!recovery_file_handle) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_handle_assign: recovery_file_handle is NULL!"); return; } if(atsc3_route_object->recovery_file_handle) { if(atsc3_route_object->recovery_file_handle != recovery_file_handle) { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_recovery_file_handle_assign: existing atsc3_route_object->recovery_file_handle is: %p, new is: %p, releasing atsc3_route_object handle!", atsc3_route_object->recovery_file_handle, recovery_file_handle); fclose(atsc3_route_object->recovery_file_handle); atsc3_route_object->recovery_file_handle = NULL; } } atsc3_route_object->recovery_file_handle = recovery_file_handle; } void atsc3_route_object_recovery_file_handle_flush_and_close(atsc3_route_object_t* atsc3_route_object) { if(atsc3_route_object && atsc3_route_object->recovery_file_buffer) { atsc3_route_object_recovery_file_buffer_flush_block_to_temporary_object_recovery_filename(atsc3_route_object); } //just to be safe if(atsc3_route_object->recovery_file_buffer) { block_Destroy(&atsc3_route_object->recovery_file_buffer); } atsc3_route_object->recovery_file_buffer_position = -1; if(atsc3_route_object->recovery_file_handle) { fclose(atsc3_route_object->recovery_file_handle); atsc3_route_object->recovery_file_handle = NULL; } } void atsc3_route_object_recovery_file_handle_abandon_and_close(atsc3_route_object_t* atsc3_route_object) { if(atsc3_route_object->recovery_file_buffer) { block_Destroy(&atsc3_route_object->recovery_file_buffer); } atsc3_route_object->recovery_file_buffer_position = -1; if(atsc3_route_object->recovery_file_handle) { fclose(atsc3_route_object->recovery_file_handle); atsc3_route_object->recovery_file_handle = NULL; } } void atsc3_route_object_calculate_expected_route_object_lct_packet_count(atsc3_route_object_t* atsc3_route_object, atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received) { //always use the MAX of our lct_packet_len so we don't indadvertantly grow our target count upwards on the final packet (short payload) atsc3_route_object->expected_route_object_lct_packet_len_for_count = __MAX(atsc3_route_object->expected_route_object_lct_packet_len_for_count, atsc3_route_object_lct_packet_received->packet_len); uint32_t route_object_lct_packet_received_target_count = __MAX(1, (atsc3_route_object->object_length / (__MAX(atsc3_route_object->expected_route_object_lct_packet_len_for_count, 1)))); atsc3_route_object->expected_route_object_lct_packet_count = route_object_lct_packet_received_target_count; #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_calculate_expected_route_object_lct_packet_count: tsi: %d, toi: %d, object_length: %d, lct_packet_len: %d, expected_route_object_lct_packet_len_for_count: %d, expected_route_object_lct_packet_count: %d, current count: %d, threshold: %d", atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->object_length, atsc3_route_object_lct_packet_received->packet_len, atsc3_route_object->expected_route_object_lct_packet_len_for_count, atsc3_route_object->expected_route_object_lct_packet_count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, (atsc3_route_object->expected_route_object_lct_packet_count * 7) / 8); #endif } /* jjustman-2021-02-03 - fix for use_sbn_esi comparator to use sbn_esi_merged */ int atsc3_route_object_lct_packet_received_generic_sbn_start_offset_comparator(const void *a_dp, const void *b_dp) { atsc3_route_object_lct_packet_received_t* a = *(atsc3_route_object_lct_packet_received_t**)a_dp; atsc3_route_object_lct_packet_received_t* b = *(atsc3_route_object_lct_packet_received_t**)b_dp; if(a->use_sbn_esi && b->use_sbn_esi) { _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_lct_packet_received_generic_sbn_start_offset_comparator, using sbn_esi, with a: %d, b: %d", a->sbn, b->sbn); if ( a->sbn_esi_merged < b->sbn_esi_merged) return -1; if ( a->sbn_esi_merged == b->sbn_esi_merged) return 0; if ( a->sbn_esi_merged > b->sbn_esi_merged) return 1; } else if(a->use_start_offset && b->use_start_offset) { if ( a->start_offset < b->start_offset) return -1; if ( a->start_offset == b->start_offset) return 0; if ( a->start_offset > b->start_offset) return 1; } else { _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_lct_packet_received_generic_sbn_start_offset_comparator: mismatched a: use_sbn_esi: %d, use_start_offset: %d, b: use_sbn_esi: %d, use_start_offset: %d", a->use_sbn_esi, a->use_start_offset, b->use_sbn_esi, b->use_start_offset); } return 0; } //jjustman-2020-07-28 - first try, check to make sure we have all of our lct_packet's received and the most recent packet would be // a fully recovered object... /* * method 1: estimate total lct_packets needed for this object - results in lots of overhead with large objects (~100's of qsort calls for one object) * //short-circuit if we don't have at least 7/8 of route_object_lct_packets from estimate (-2 for single digit lct_packet counts that may get lost...) //or only do this calculation of packet_len ~ object_len? int expected_route_object_lct_packet_count_threshold_adjusted = __MAX(1, (((int)atsc3_route_object->expected_route_object_lct_packet_count * 7) / 8) - 2); uint32_t expected_route_object_lct_packet_count_threshold = (uint32_t)expected_route_object_lct_packet_count_threshold_adjusted; if(atsc3_route_object->atsc3_route_object_lct_packet_received_v.count < expected_route_object_lct_packet_count_threshold) { #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_is_complete: tsi: %d, toi: %d, pre-flight check with atsc3_route_object->atsc3_route_object_lct_packet_received_v.count: %d, expected_route_object_lct_packet_count_threshold: %d", atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, expected_route_object_lct_packet_count_threshold); #endif return false; } #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: BEFORE qsort loop: %d, using start_offset - tsi: %d, toi: %d, last_object_position: %d, use start offset: %d, start_offset: %d, packet_len: %d", i, atsc3_route_object->tsi, atsc3_route_object->toi, last_object_position, atsc3_route_object_lct_packet_received->use_start_offset, atsc3_route_object_lct_packet_received->start_offset, atsc3_route_object_lct_packet_received->packet_len); last_object_position += atsc3_route_object_lct_packet_received->packet_len; } last_object_position = 0; #endif */ //#define __ATSC3_ROUTE_OBJECT_PENDANTIC__ //#define __ATSC3_JJ_PENDANTIC_2021_07_07__ bool atsc3_route_object_is_complete(atsc3_route_object_t* atsc3_route_object) { atsc3_route_object_lct_packet_received_t* atsc3_route_object_lct_packet_received = NULL; bool has_missing_source_blocks = false; uint32_t last_object_position = 0; uint64_t total_bytes_recovered = 0; #ifdef __ATSC3_JJ_PENDANTIC_2021_07_07__ for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; total_bytes_recovered += atsc3_route_object_lct_packet_received->packet_len; } _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d, total_bytes_recovered: %"PRIu64, atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, total_bytes_recovered); if(atsc3_route_object->tsi == 7 && atsc3_route_object->toi == 5) { _ATSC3_ROUTE_OBJECT_INFO("atsc3_route_object_is_complete: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d, total_bytes_recovered: %"PRIu64, atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, total_bytes_recovered); } #endif int atsc3_route_object_length_threshold = __MAX(1, (int)atsc3_route_object->object_length - 1500); if(atsc3_route_object->recovery_complete_timestamp) { _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: true, using recovery_complete_timestamp, atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d, recovery_complete_timestamp: %lu, final_object_recovery_filename_for_logging: %s", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->recovery_complete_timestamp, atsc3_route_object->final_object_recovery_filename_for_logging); return true; } //short circuit in that our cumulative_lct_packet_len should be close to our object length if(atsc3_route_object->cumulative_lct_packet_len < atsc3_route_object_length_threshold) { #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_is_complete: tsi: %d, toi: %d, pre-flight check with atsc3_route_object->atsc3_route_object_lct_packet_received_v.count: %d, cumulative_lct_packet_len: %d, < atsc3_route_object_length_threshold: %d", atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->cumulative_lct_packet_len, atsc3_route_object_length_threshold); #endif return false; } qsort((void**)atsc3_route_object->atsc3_route_object_lct_packet_received_v.data, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, sizeof(atsc3_route_object_lct_packet_received_t**), atsc3_route_object_lct_packet_received_generic_sbn_start_offset_comparator); #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_is_complete: AFTER qsort loop: %d, using start_offset - tsi: %d, toi: %d, use start offset: %d, start_offset: %d, packet_len: %d, computed last_object_position: %d", i, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object_lct_packet_received->use_start_offset, atsc3_route_object_lct_packet_received->start_offset, atsc3_route_object_lct_packet_received->packet_len, last_object_position); last_object_position += atsc3_route_object_lct_packet_received->packet_len; } last_object_position = 0; #endif for(int i=0; i < atsc3_route_object->atsc3_route_object_lct_packet_received_v.count && !has_missing_source_blocks; i++) { atsc3_route_object_lct_packet_received = atsc3_route_object->atsc3_route_object_lct_packet_received_v.data[i]; if(atsc3_route_object_lct_packet_received->use_sbn_esi) { if(last_object_position != atsc3_route_object_lct_packet_received->esi) { has_missing_source_blocks = true; #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: has_missing_source_blocks - using sbn_esi - tsi: %d, toi: %d, last_object_position: %d, esi: %d", atsc3_route_object->tsi, atsc3_route_object->toi, last_object_position, atsc3_route_object_lct_packet_received->esi); #endif } else { last_object_position += atsc3_route_object_lct_packet_received->packet_len; } } else if(atsc3_route_object_lct_packet_received->use_start_offset) { if(last_object_position != atsc3_route_object_lct_packet_received->start_offset) { has_missing_source_blocks = true; #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_is_complete: has_missing_source_blocks - using start_offset - idx: %d, tsi: %d, toi: %d, last_object_position: %d, start_offset: %d", i, atsc3_route_object->tsi, atsc3_route_object->toi, last_object_position, atsc3_route_object_lct_packet_received->start_offset); #endif } else { #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: loop: %d, using start_offset - tsi: %d, toi: %d, last_object_position: %d, start_offset: %d, packet_len: %d", i, atsc3_route_object->tsi, atsc3_route_object->toi, last_object_position, atsc3_route_object_lct_packet_received->start_offset, atsc3_route_object_lct_packet_received->packet_len); #endif last_object_position += atsc3_route_object_lct_packet_received->packet_len; } } } if(!atsc3_route_object->object_length || last_object_position != atsc3_route_object->object_length) { _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_is_complete: false, has_missing_source_blocks at end, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v: %d, last_object_position: %d, atsc3_route_object->object_length: %d", atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, last_object_position, atsc3_route_object->object_length); has_missing_source_blocks = true; } else { _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_is_complete: true, object_length: %8d, atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d, recovery_complete_timestamp: %lu, final_object_recovery_filename_for_logging: %s", atsc3_route_object->object_length, atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->recovery_complete_timestamp, atsc3_route_object->final_object_recovery_filename_for_logging); } return !has_missing_source_blocks; } /* * jjustman-2020-07-28 - atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: * * frees atsc3_route_bject_lct_packet_received objects, and removes as candidate from "given_up" eviction, but will NOT unlink temporary or final object recovery filenames * * used for SLS flows * */ void atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received(atsc3_route_object_t* atsc3_route_object) { #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: before: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count); #endif atsc3_route_object_recovery_file_handle_flush_and_close(atsc3_route_object); //jjustman-2020-08-04 - important, always call these two together.. atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); atsc3_route_object->is_toi_init = false; atsc3_route_object->expected_route_object_lct_packet_count = 0; atsc3_route_object->expected_route_object_lct_packet_len_for_count = 0; atsc3_route_object->cumulative_lct_packet_len = 0; freeclean((void**)&atsc3_route_object->temporary_object_recovery_filename); freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_eviction); #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: after: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count); #endif } /* * jjustman-2020-07-28 - atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received: * * frees atsc3_route_bject_lct_packet_received objects, and removes as candidate from "given_up" eviction, and WILL unlink temporary/final object recovery on disk after * * used for media fragment cleanup when atsc3_route_object_set_final_object_recovery_filename_for_eviction(atsc3_route_object, new_file_name); is set * * invoked from atsc3_lls_sls_alc_monitor_check_all_s_tsid_flows_has_given_up_route_objects */ void atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received(atsc3_route_object_t* atsc3_route_object) { #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: before: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count); #endif _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received: p: %p, tsi: %d, toi: %d, before closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d)", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size ); atsc3_route_object_recovery_file_handle_abandon_and_close(atsc3_route_object); //jjustman-2020-08-04 - important, always call these two together.. atsc3_route_object_free_atsc3_route_object_lct_packet_received(atsc3_route_object); atsc3_route_object->most_recent_atsc3_route_object_lct_packet_received = NULL; atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object); atsc3_route_object->is_toi_init = false; atsc3_route_object->expected_route_object_lct_packet_count = 0; atsc3_route_object->expected_route_object_lct_packet_len_for_count = 0; atsc3_route_object->cumulative_lct_packet_len = 0; //jjustman-2020-07-28: unlink temporary_object_recovery_filename if(atsc3_route_object->temporary_object_recovery_filename) { struct stat st = {0}; if(stat(atsc3_route_object->temporary_object_recovery_filename, &st) == 0) { _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received: removing temporary_object_recovery_filename: %s", atsc3_route_object->temporary_object_recovery_filename); remove(atsc3_route_object->temporary_object_recovery_filename); } freeclean((void**)&atsc3_route_object->temporary_object_recovery_filename); } //jjustman-2020-07-28: unlink final_object_recovery_filename_for_eviction if(atsc3_route_object->final_object_recovery_filename_for_eviction) { struct stat st = {0}; if(stat(atsc3_route_object->final_object_recovery_filename_for_eviction, &st) == 0) { _ATSC3_ROUTE_OBJECT_TRACE("atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received: removing final_object_recovery_filename_for_eviction: %s", atsc3_route_object->final_object_recovery_filename_for_eviction); remove(atsc3_route_object->final_object_recovery_filename_for_eviction); } freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_eviction); } #ifdef __ATSC3_ROUTE_OBJECT_PENDANTIC__ _ATSC3_ROUTE_OBJECT_WARN("atsc3_route_object_reset_and_free_atsc3_route_object_lct_packet_received: after: atsc3_route_object: %p, tsi: %d, toi: %d, atsc3_route_object_lct_packet_received_v.count: %d", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count); #endif _ATSC3_ROUTE_OBJECT_DEBUG("atsc3_route_object_reset_and_free_and_unlink_recovery_file_atsc3_route_object_lct_packet_received: p: %p, tsi: %d, toi: %d, after closing fp: %p, atsc3_route_object_lct_packet_received count: %d (size: %d), final_object_recovery_filename_for_logging: %s", atsc3_route_object, atsc3_route_object->tsi, atsc3_route_object->toi, atsc3_route_object->recovery_file_handle, atsc3_route_object->atsc3_route_object_lct_packet_received_v.count, atsc3_route_object->atsc3_route_object_lct_packet_received_v.size, atsc3_route_object->final_object_recovery_filename_for_logging ); freeclean((void**)&atsc3_route_object->final_object_recovery_filename_for_logging); } void atsc3_route_object_free_lct_packet_received_tree(atsc3_route_object_t* atsc3_route_object) { if(!atsc3_route_object) { return; } //clean up our stale avltree entries struct avltree_node* node; while((node = avltree_first(&atsc3_route_object->atsc3_route_object_lct_packet_received_tree))) { avltree_remove(node, &atsc3_route_object->atsc3_route_object_lct_packet_received_tree); atsc3_route_object_lct_packet_received_node_t *p = avltree_container_of(node, atsc3_route_object_lct_packet_received_node_t, node); freesafe((void*)p); } //clear out any remaining pointers just to be safe...does not alloc just sets everything to NULL avltree_init(&atsc3_route_object->atsc3_route_object_lct_packet_received_tree, atsc3_route_object_lct_packet_received_cmp_fn, 0); } /* jjustman-2019-09-17: TODO - free temporary filename when done */ char* alc_packet_dump_to_object_get_temporary_recovering_filename(udp_flow_t *udp_flow, atsc3_alc_packet_t *alc_packet) { char* temporary_file_name = (char *)calloc(256, sizeof(char)); if(alc_packet->def_lct_hdr) { snprintf(temporary_file_name, 255, "%s%u.%u.%u.%u.%u.%u-%u.recovering", __ALC_DUMP_OUTPUT_PATH__, __toipandportnonstruct(udp_flow->dst_ip_addr, udp_flow->dst_port), alc_packet->def_lct_hdr->tsi, alc_packet->def_lct_hdr->toi); } return temporary_file_name; }
ben-EDT/libatsc3
src/atsc3_audio_decoder_configuration_record.h
<filename>src/atsc3_audio_decoder_configuration_record.h // // Created by <NAME> on 12/1/20. // #include <stddef.h> #include <stdlib.h> #ifndef ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_H_ #define ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_H_ #include "atsc3_logging_externs.h" #include "atsc3_vector_builder.h" #include "atsc3_isobmff_box_parser_tools.h" #ifdef __cplusplus extern "C" { #endif typedef struct atsc3_audio_ac4_specific_box { uint32_t box_size; //preceeding isobmff box size uint32_t type; //dac4 fourcc code uint8_t ac4_dsi_version:3; uint8_t bitstream_version:7; uint8_t fs_index:1; //This field shall contain the sampling frequency index as described in clause 4.3.3.2.5. Its value shall be Its value shall be the same as read from the ac4_toc, 0: 44100, 1: 48000 uint8_t frame_rate_index:4; uint16_t n_presentations:9; //additional parsing as needed... } atsc3_audio_ac4_specific_box_t; /* atsc3_audio_ac4_sample_entry_box: * min. size: at least 45 bytes */ typedef struct atsc3_audio_ac4_sample_entry_box { uint32_t box_size; //preceeding isobmff box size uint32_t type; //ac-4 fourcc code uint8_t reserved_48[6]; //6 bytes reserved uint16_t data_reference_index; uint32_t reserved_64[2]; //8 bytes reserved uint16_t channel_count; //The ChannelCount field should be set to the total number of audio output channels of the default presentation of that track, if not defined differently by an application standard uint16_t sample_size; //value 16 uint32_t reserved_32; //4 bytes reserved uint16_t sampling_frequency; uint16_t reserved_16; //2 bytes reserved //assumed required that if we are ac4_sample, then we must have an ac4_specific box atsc3_audio_ac4_specific_box_t atsc3_audio_ac4_specific_box; } atsc3_audio_ac4_sample_entry_box_t; typedef struct atsc3_audio_decoder_configuration_record { char asset_type[4]; //fourcc - extracted from mmtp_packet_id_packets_container //extracted from moov/init segment uint16_t channel_count; uint16_t sample_depth; uint32_t sample_rate; uint32_t timebase; //14496-12:2015 - timescale is uint32_t //extracted from moof/fragment metadata uint32_t sample_duration_us; //14496-12:2015 - duration is uint32_t atsc3_audio_ac4_sample_entry_box_t* atsc3_audio_ac4_sample_entry_box; //todo: jjustman-2020-12-01 - add in stsd child fourcc code and isobmff box in block_t format } atsc3_audio_decoder_configuration_record_t; atsc3_audio_decoder_configuration_record_t* atsc3_audio_decoder_configuration_record_new(); void atsc3_audio_decoder_configuration_record_free(atsc3_audio_decoder_configuration_record_t** atsc3_audio_decoder_configuration_record_p); atsc3_audio_ac4_sample_entry_box_t* atsc3_audio_ac4_sample_entry_box_new(); atsc3_audio_ac4_sample_entry_box_t* atsc3_audio_decoder_ac4_parse_init_box_from_block_t(block_t* mmt_mpu_metadata_block); void atsc3_audio_ac4_sample_entry_box_dump(atsc3_audio_ac4_sample_entry_box_t* atsc3_audio_ac4_sample_entry_box); atsc3_audio_decoder_configuration_record_t* atsc3_audio_decoder_configuration_record_parse_from_asset_type_and_block_t(char asset_type_fourcc[4], block_t* mmt_mpu_metadata_block); atsc3_audio_decoder_configuration_record_t* atsc3_audio_decoder_configuration_record_parse_from_block_t(block_t* mmt_mpu_metadata_block); bool atsc3_audio_decoder_configuration_parse_codec_type_and_sample_rate_from_block_t(atsc3_audio_decoder_configuration_record_t* atsc3_audio_decoder_configuration_record, block_t* mmt_mpu_metadata_block); #define _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_ERROR(...) __LIBATSC3_TIMESTAMP_ERROR(__VA_ARGS__); #define _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_WARN(...) __LIBATSC3_TIMESTAMP_WARN(__VA_ARGS__); #define _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_INFO(...) if(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_INFO_ENABLED) { __LIBATSC3_TIMESTAMP_INFO(__VA_ARGS__); } #define _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_DEBUG(...) if(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_DEBUG_ENABLED) { __LIBATSC3_TIMESTAMP_DEBUG(__VA_ARGS__); } #define _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_TRACE(...) if(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_TRACE_ENABLED) { __LIBATSC3_TIMESTAMP_TRACE(__VA_ARGS__); } #ifdef __cplusplus } #endif #endif //ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_H_
ben-EDT/libatsc3
src/atsc3_logging_externs.h
<filename>src/atsc3_logging_externs.h /* * atsc3_logging_externs.h * * Created on: Mar 6, 2019 * Author: jjustman */ #include <stdio.h> /* printf */ #include <stdarg.h> /* va_list, va_start, va_arg, va_end */ #include "atsc3_utils.h" #ifndef ATSC3_LOGGING_EXTERNS_H_ #define ATSC3_LOGGING_EXTERNS_H_ #ifdef __cplusplus extern "C" { #endif //#ifdef __LIBATSC3_ANDROID__ //#include <android/log.h> //#define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "TAG", __VA_ARGS__); //#endif #include <stdarg.h> #include <string.h> #include <stdio.h> #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) #define ATSC3_LOGS_LIST \ X(_ATSC3_UTILS_INFO_ENABLED) \ X(_ATSC3_UTILS_DEBUG_ENABLED) \ X(_ATSC3_UTILS_TRACE_ENABLED) \ X(_ATSC3_UDP_INFO_ENABLED) \ X(_ATSC3_UDP_DEBUG_ENABLED) \ X(_ATSC3_UDP_TRACE_ENABLED) \ X(_ALP_PARSER_INFO_ENABLED) \ X(_ALP_PARSER_DEBUG_ENABLED) \ X(_ALP_PARSER_TRACE_ENABLED) \ X(_XML_INFO_ENABLED) \ X(_XML_DEBUG_ENABLED) \ X(_XML_TRACE_ENABLED) \ X(_LLS_INFO_ENABLED) \ X(_LLS_DEBUG_ENABLED) \ X(_LLS_TRACE_ENABLED) \ X(_LLS_TYPES_INFO_ENABLED) \ X(_LLS_TYPES_DEBUG_ENABLED) \ X(_LLS_TYPES_TRACE_ENABLED) \ X(_LLS_SLT_PARSER_INFO_ENABLED) \ X(_LLS_SLT_PARSER_INFO_MMT_ENABLED) \ X(_LLS_SLT_PARSER_INFO_ROUTE_ENABLED) \ X(_SLS_METADATA_FRAGMENT_PARSER_INFO_ENABLED) \ X(_SLS_METADATA_FRAGMENT_PARSER_DEBUG_ENABLED) \ X(_SLS_METADATA_FRAGMENT_PARSER_TRACE_ENABLED) \ X(_FDT_PARSER_DEBUG_ENABLED) \ X(_LLS_SLT_PARSER_DEBUG_ENABLED) \ X(_LLS_SLT_PARSER_TRACE_ENABLED) \ X(_LLS_ALC_UTILS_INFO_ENABLED) \ X(_LLS_ALC_UTILS_DEBUG_ENABLED) \ X(_LLS_ALC_UTILS_TRACE_ENABLED) \ X(_LLS_MMT_UTILS_INFO_ENABLED) \ X(_LLS_MMT_UTILS_DEBUG_ENABLED) \ X(_LLS_MMT_UTILS_TRACE_ENABLED) \ X(_ROUTE_SLS_PROCESSOR_INFO_ENABLED) \ X(_ROUTE_SLS_PROCESSOR_DEBUG_ENABLED) \ X(_ROUTE_SLS_PROCESSOR_TRACE_ENABLED) \ X(_ROUTE_MBMS_ENVELOPE_PARSER_INFO_ENABLED) \ X(_ROUTE_MBMS_ENVELOPE_PARSER_DEBUG_ENABLED) \ X(_ROUTE_MPD_PARSER_INFO_ENABLED) \ X(_ROUTE_MPD_PARSER_DEBUG_ENABLED) \ X(_ROUTE_S_TSID_PARSER_INFO_ENABLED) \ X(_ROUTE_S_TSID_PARSER_DEBUG_ENABLED) \ X(_ROUTE_USBD_PARSER_INFO_ENABLED) \ X(_ROUTE_USBD_PARSER_DEBUG_ENABLED)\ X(_MMTP_DEBUG_ENABLED) \ X(_MMTP_TRACE_ENABLED) \ X(_MMT_MPU_PARSER_DEBUG_ENABLED) \ X(_MMT_MPU_PARSER_TRACE_ENABLED) \ X(_MMT_MPU_DEBUG_ENABLED) \ X(_MMT_MPU_TRACE_ENABLED) \ X(_MMT_SIGNALLING_MESSAGE_ERROR_23008_1_ENABLED) \ X(_MMT_SIGNALLING_MESSAGE_INFO_ENABLED) \ X(_MMT_SIGNALLING_MESSAGE_DEBUG_ENABLED) \ X(_MMT_SIGNALLING_MESSAGE_TRACE_ENABLED) \ X(_MMT_RECON_FROM_SAMPLE_DEBUG_ENABLED) \ X(_MMT_RECON_FROM_SAMPLE_TRACE_ENABLED) \ X(_MMT_RECON_FROM_SAMPLE_SIGNAL_INFO_ENABLED) \ X(_MMT_CONTEXT_MPU_SIGNAL_INFO_ENABLED) \ X(_MMT_CONTEXT_MPU_DEBUG_ENABLED) \ X(_MMT_CONTEXT_MPU_TRACE_ENABLED) \ X(_ALC_UTILS_INFO_ENABLED) \ X(_ALC_UTILS_DEBUG_ENABLED) \ X(_ALC_UTILS_TRACE_ENABLED) \ X(_ALC_UTILS_IOTRACE_ENABLED) \ X(_ALC_RX_DEBUG_ENABLED) \ X(_ALC_RX_TRACE_ENABLED) \ X(_ALC_RX_TRACE_TAB_ENABLED) \ X(_PLAYER_FFPLAY_DEBUG_ENABLED) \ X(_PLAYER_FFPLAY_TRACE_ENABLED) \ X(_STLTP_PARSER_INFO_ENABLED) \ X(_STLTP_PARSER_DUMP_ENABLED) \ X(_STLTP_PARSER_DEBUG_ENABLED) \ X(_STLTP_PARSER_TRACE_ENABLED) \ X(_MIME_PARSER_INFO_ENABLED) \ X(_MIME_PARSER_DEBUG_ENABLED) \ X(_MIME_PARSER_TRACE_ENABLED) \ X(_IP_UDP_RTP_PARSER_INFO_ENABLED) \ X(_IP_UDP_RTP_PARSER_DEBUG_ENABLED) \ X(_IP_UDP_RTP_PARSER_TRACE_ENABLED) \ X(_STLTP_TYPES_DEBUG_ENABLED) \ X(_STLTP_TYPES_TRACE_ENABLED) \ X(_DSTP_TYPES_DEBUG_ENABLED) \ X(_DSTP_TYPES_TRACE_ENABLED) \ X(_AEAT_TYPES_INFO_ENABLED) \ X(_AEAT_TYPES_DEBUG_ENABLED) \ X(_AEAT_TYPES_TRACE_ENABLED) \ X(_A344_RECEIVER_QUERY_INFO_ENABLED) \ X(_A344_RECEIVER_QUERY_DEBUG_ENABLED) \ X(_A344_RECEIVER_QUERY_TRACE_ENABLED) \ X(_AEAT_PARSER_INFO_ENABLED) \ X(_AEAT_PARSER_DEBUG_ENABLED) \ X(_AEAT_PARSER_TRACE_ENABLED) \ X(_ATSC3_HEVC_NAL_EXTRACTOR_INFO_ENABLED) \ X(_ATSC3_HEVC_NAL_EXTRACTOR_DEBUG_ENABLED) \ X(_ATSC3_HEVC_NAL_EXTRACTOR_TRACE_ENABLED) \ X(_ATSC3_PCAP_TYPE_DEBUG_ENABLED) \ X(_ATSC3_PCAP_TYPE_TRACE_ENABLED) \ X(_SL_TLV_DEMOD_DEBUG_ENABLED) \ X(_SL_TLV_DEMOD_TRACE_ENABLED) \ X(_PCRE2_REGEX_UTILS_INFO_ENABLED) \ X(_PCRE2_REGEX_UTILS_DEBUG_ENABLED) \ X(_PCRE2_REGEX_UTILS_TRACE_ENABLED) \ X(_ROUTE_PACKAGE_UTILS_DEBUG_ENABLED) \ X(_ROUTE_PACKAGE_UTILS_TRACE_ENABLED) \ X(_ROUTE_DASH_UTILS_INFO_ENABLED) \ X(_ROUTE_DASH_UTILS_DEBUG_ENABLED) \ X(_ROUTE_DASH_UTILS_TRACE_ENABLED) \ X(_ROUTE_OBJECT_INFO_ENABLED) \ X(_ROUTE_OBJECT_DEBUG_ENABLED) \ X(_ROUTE_OBJECT_TRACE_ENABLED) \ X(_SLS_ALC_FLOW_INFO_ENABLED) \ X(_SLS_ALC_FLOW_DEBUG_ENABLED) \ X(_SLS_ALC_FLOW_TRACE_ENABLED) \ X(_HELD_PARSER_INFO_ENABLED) \ X(_HELD_PARSER_DEBUG_ENABLED) \ X(_HELD_PARSER_TRACE_ENABLED) \ X(_ATSC3_STLTP_DEPACKETIZER_INFO_ENABLED) \ X(_ATSC3_STLTP_DEPACKETIZER_DEBUG_ENABLED) \ X(_ATSC3_STLTP_DEPACKETIZER_TRACE_ENABLED) \ X(_ATSC3_ALP_TYPES_INFO_ENABLED) \ X(_ATSC3_ALP_TYPES_DUMP_ENABLED) \ X(_ATSC3_ALP_TYPES_DEBUG_ENABLED) \ X(_ATSC3_ALP_TYPES_TRACE_ENABLED) \ X(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_INFO_ENABLED) \ X(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_DEBUG_ENABLED) \ X(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_TRACE_ENABLED) \ X(_ATSC3_ISOBMFF_BOX_PARSER_TOOLS_INFO_ENABLED) \ X(_ATSC3_ISOBMFF_BOX_PARSER_TOOLS_DEBUG_ENABLED) \ X(_ATSC3_ISOBMFF_BOX_PARSER_TOOLS_TRACE_ENABLED) \ X(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_INFO_ENABLED) \ X(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_DEBUG_ENABLED) \ X(_ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_TRACE_ENABLED) \ X(_ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_INFO_ENABLED) \ X(_ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_DEBUG_ENABLED) \ X(_ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_TRACE_ENABLED) \ X(_ATSC3_STLTP_DEPACKETIZER_CONTEXT_INFO_ENABLED) \ X(_ATSC3_STLTP_DEPACKETIZER_CONTEXT_DEBUG_ENABLED) #define X(name) extern int name; ATSC3_LOGS_LIST #undef X //extern int _ATSC3_UDP_INFO_ENABLED; //extern int _ATSC3_UDP_DEBUG_ENABLED; //extern int _ATSC3_UDP_TRACE_ENABLED; // //extern int _ALP_PARSER_INFO_ENABLED; //extern int _ALP_PARSER_DEBUG_ENABLED; //extern int _ALP_PARSER_TRACE_ENABLED; // //extern int _XML_INFO_ENABLED; //extern int _XML_DEBUG_ENABLED; //extern int _XML_TRACE_ENABLED; // //extern int _LLS_INFO_ENABLED; //extern int _LLS_DEBUG_ENABLED; //extern int _LLS_TRACE_ENABLED; // //extern int _LLS_TYPES_INFO_ENABLED; //extern int _LLS_TYPES_DEBUG_ENABLED; //extern int _LLS_TYPES_TRACE_ENABLED; // //extern int _LLS_SLT_PARSER_INFO_ENABLED; //extern int _LLS_SLT_PARSER_INFO_MMT_ENABLED; //extern int _LLS_SLT_PARSER_INFO_ROUTE_ENABLED; // //extern int _SLS_METADATA_FRAGMENT_PARSER_INFO_ENABLED; //extern int _SLS_METADATA_FRAGMENT_PARSER_DEBUG_ENABLED; //extern int _SLS_METADATA_FRAGMENT_PARSER_TRACE_ENABLED; // //extern int _FDT_PARSER_DEBUG_ENABLED; // //extern int _LLS_SLT_PARSER_DEBUG_ENABLED; //extern int _LLS_SLT_PARSER_TRACE_ENABLED; // //extern int _LLS_ALC_UTILS_INFO_ENABLED; //extern int _LLS_ALC_UTILS_DEBUG_ENABLED; //extern int _LLS_ALC_UTILS_TRACE_ENABLED; // //extern int _LLS_MMT_UTILS_INFO_ENABLED; //extern int _LLS_MMT_UTILS_DEBUG_ENABLED; //extern int _LLS_MMT_UTILS_TRACE_ENABLED; // //extern int _ROUTE_SLS_PROCESSOR_INFO_ENABLED; //extern int _ROUTE_SLS_PROCESSOR_DEBUG_ENABLED; //extern int _ROUTE_SLS_PROCESSOR_TRACE_ENABLED; // //extern int _ROUTE_MBMS_ENVELOPE_PARSER_INFO_ENABLED; //extern int _ROUTE_MBMS_ENVELOPE_PARSER_DEBUG_ENABLED; // //extern int _ROUTE_MPD_PARSER_INFO_ENABLED; //extern int _ROUTE_MPD_PARSER_DEBUG_ENABLED; // //extern int _ROUTE_S_TSID_PARSER_INFO_ENABLED; //extern int _ROUTE_S_TSID_PARSER_DEBUG_ENABLED; // //extern int _ROUTE_USBD_PARSER_INFO_ENABLED; //extern int _ROUTE_USBD_PARSER_DEBUG_ENABLED; extern int _MPU_DEBUG_ENABLED; //extern int _MMTP_DEBUG_ENABLED; //extern int _MMTP_TRACE_ENABLED; // //extern int _MMT_MPU_PARSER_DEBUG_ENABLED; //extern int _MMT_MPU_PARSER_TRACE_ENABLED; // //extern int _MMT_MPU_DEBUG_ENABLED; //extern int _MMT_MPU_TRACE_ENABLED; // //extern int _MMT_SIGNALLING_MESSAGE_ERROR_23008_1_ENABLED; //extern int _MMT_SIGNALLING_MESSAGE_DEBUG_ENABLED; //extern int _MMT_SIGNALLING_MESSAGE_TRACE_ENABLED; // //extern int _MMT_RECON_FROM_SAMPLE_DEBUG_ENABLED; //extern int _MMT_RECON_FROM_SAMPLE_TRACE_ENABLED; // //extern int _MMT_RECON_FROM_SAMPLE_SIGNAL_INFO_ENABLED; // ////mmt context callback logging //extern int _MMT_CONTEXT_MPU_SIGNAL_INFO_ENABLED; //extern int _MMT_CONTEXT_MPU_DEBUG_ENABLED; //extern int _MMT_CONTEXT_MPU_TRACE_ENABLED; // //extern int _ALC_UTILS_DEBUG_ENABLED; //extern int _ALC_UTILS_TRACE_ENABLED; //extern int _ALC_UTILS_IOTRACE_ENABLED; // //extern int _ALC_RX_DEBUG_ENABLED; //extern int _ALC_RX_TRACE_ENABLED; //extern int _ALC_RX_TRACE_TAB_ENABLED; // //extern int _PLAYER_FFPLAY_DEBUG_ENABLED; //extern int _PLAYER_FFPLAY_TRACE_ENABLED; // //extern int _STLTP_PARSER_INFO_ENABLED; //extern int _STLTP_PARSER_DUMP_ENABLED; //extern int _STLTP_PARSER_DEBUG_ENABLED; //extern int _STLTP_PARSER_TRACE_ENABLED; // //extern int _MIME_PARSER_INFO_ENABLED; //extern int _MIME_PARSER_DEBUG_ENABLED; //extern int _MIME_PARSER_TRACE_ENABLED; // //extern int _IP_UDP_RTP_PARSER_INFO_ENABLED; //extern int _IP_UDP_RTP_PARSER_DEBUG_ENABLED; //extern int _IP_UDP_RTP_PARSER_TRACE_ENABLED; // //extern int _STLTP_TYPES_DEBUG_ENABLED; //extern int _STLTP_TYPES_TRACE_ENABLED; // //extern int _DSTP_TYPES_DEBUG_ENABLED; //extern int _DSTP_TYPES_TRACE_ENABLED; // //extern int _AEAT_TYPES_INFO_ENABLED; //extern int _AEAT_TYPES_DEBUG_ENABLED; //extern int _AEAT_TYPES_TRACE_ENABLED; // //extern int _A344_RECEIVER_QUERY_INFO_ENABLED; //extern int _A344_RECEIVER_QUERY_DEBUG_ENABLED; //extern int _A344_RECEIVER_QUERY_TRACE_ENABLED; // //extern int _AEAT_PARSER_INFO_ENABLED; //extern int _AEAT_PARSER_DEBUG_ENABLED; //extern int _AEAT_PARSER_TRACE_ENABLED; // //extern int _ATSC3_HEVC_NAL_EXTRACTOR_INFO_ENABLED; //extern int _ATSC3_HEVC_NAL_EXTRACTOR_DEBUG_ENABLED; //extern int _ATSC3_HEVC_NAL_EXTRACTOR_TRACE_ENABLED; // //extern int _ATSC3_PCAP_TYPE_DEBUG_ENABLED; //extern int _ATSC3_PCAP_TYPE_TRACE_ENABLED; // //extern int _SL_TLV_DEMOD_DEBUG_ENABLED; //extern int _SL_TLV_DEMOD_TRACE_ENABLED; // //extern int _PCRE2_REGEX_UTILS_INFO_ENABLED; //extern int _PCRE2_REGEX_UTILS_DEBUG_ENABLED; //extern int _PCRE2_REGEX_UTILS_TRACE_ENABLED; // //extern int _ROUTE_PACKAGE_UTILS_DEBUG_ENABLED; //extern int _ROUTE_PACKAGE_UTILS_TRACE_ENABLED; // //extern int _ROUTE_DASH_UTILS_INFO_ENABLED; //extern int _ROUTE_DASH_UTILS_DEBUG_ENABLED; //extern int _ROUTE_DASH_UTILS_TRACE_ENABLED; // //extern int _ROUTE_OBJECT_INFO_ENABLED; //extern int _ROUTE_OBJECT_DEBUG_ENABLED; //extern int _ROUTE_OBJECT_TRACE_ENABLED; // //extern int _SLS_ALC_FLOW_INFO_ENABLED; //extern int _SLS_ALC_FLOW_DEBUG_ENABLED; //extern int _SLS_ALC_FLOW_TRACE_ENABLED; // //extern int _HELD_PARSER_INFO_ENABLED; //extern int _HELD_PARSER_DEBUG_ENABLED; //extern int _HELD_PARSER_TRACE_ENABLED; // //extern int _ATSC3_STLTP_DEPACKETIZER_INFO_ENABLED; //extern int _ATSC3_STLTP_DEPACKETIZER_DEBUG_ENABLED; //extern int _ATSC3_STLTP_DEPACKETIZER_TRACE_ENABLED; extern int _ATSC3_PCAP_STLTP_VIRTUAL_PHY_INFO_ENABLED; extern int _ATSC3_PCAP_STLTP_VIRTUAL_PHY_DEBUG_ENABLED; extern int _ATSC3_PCAP_STLTP_VIRTUAL_PHY_TRACE_ENABLED; //extern int _ATSC3_ALP_TYPES_INFO_ENABLED; //extern int _ATSC3_ALP_TYPES_DUMP_ENABLED; //extern int _ATSC3_ALP_TYPES_DEBUG_ENABLED; //extern int _ATSC3_ALP_TYPES_TRACE_ENABLED; // // //extern int _ATSC3_CORE_SERVICE_PLAYER_BRIDGE_INFO_ENABLED; //extern int _ATSC3_CORE_SERVICE_PLAYER_BRIDGE_DEBUG_ENABLED; //extern int _ATSC3_CORE_SERVICE_PLAYER_BRIDGE_TRACE_ENABLED; // // //extern int _ATSC3_ISOBMFF_BOX_PARSER_TOOLS_INFO_ENABLED; //extern int _ATSC3_ISOBMFF_BOX_PARSER_TOOLS_DEBUG_ENABLED; //extern int _ATSC3_ISOBMFF_BOX_PARSER_TOOLS_TRACE_ENABLED; // //extern int _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_INFO_ENABLED; //extern int _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_DEBUG_ENABLED; //extern int _ATSC3_AUDIO_DECODER_CONFIGURATION_RECORD_TRACE_ENABLED; // //extern int _ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_INFO_ENABLED; //extern int _ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_DEBUG_ENABLED; //extern int _ATSC3_MMT_MFU_CONTEXT_CALLBACKS_DEFAULT_JNI_TRACE_ENABLED; extern int _ATSC3_LOWASIS_PHY_RXDATA_ANDROID_INFO_ENABLED; extern int _ATSC3_LOWASIS_PHY_RXDATA_ANDROID_DEBUG_ENABLED; extern int _ATSC3_LOWASIS_PHY_RXDATA_ANDROID_TRACE_ENABLED; //extern int _ATSC3_STLTP_DEPACKETIZER_CONTEXT_INFO_ENABLED; //extern int _ATSC3_STLTP_DEPACKETIZER_CONTEXT_DEBUG_ENABLED; extern int _ATSC3_SRTRXSTLTPVIRTUALPHY_INFO_ENABLED; extern int _ATSC3_SRTRXSTLTPVIRTUALPHY_DEBUG_ENABLED; extern int _ATSC3_SRTRXSTLTPVIRTUALPHY_TRACE_ENABLED; //c++ linkage //extern int _ISOBMFFTRACKJOINER_DEBUG_ENABLED; //jjustman-2019-07-24 - normaolized debug logging format #ifdef __ANDROID__ typedef enum { #define X(name) _##name, ATSC3_LOGS_LIST #undef X ATSC3_CORE_LOGS_COUNT } atsc3_core_log_t; static const char* ATSC3_CORE_LOGS_STR[ATSC3_CORE_LOGS_COUNT] = { #define X(name) [_##name] = #name, ATSC3_LOGS_LIST #undef X }; static int* ATSC3_CORE_LOGS_PTR[ATSC3_CORE_LOGS_COUNT] = { #define X(name) [_##name] = &name, ATSC3_LOGS_LIST #undef X }; #define __ANDROID_MAX_LOG_LINE_LENGTH__ 1025 extern char __ANDROID_LOG_VPRINTF_BUFFER[]; // vsnprintf(char * restrict str, size_t size, const char * restrict format, va_list ap); //va_list argptr; va_start(argptr, format); //__VA_OPT__(,) __VA_ARGS__ #define __LIBATSC3_TIMESTAMP_ERROR(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:ERROR:%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_WARN(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:WARN :%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_INFO(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:INFO :%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_DUMP(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:DUMP :%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_DEBUG(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:DEBUG:%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_TAB_DEBUG(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:DEBUG:%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_TRACE(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:TRACE:%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __LIBATSC3_TIMESTAMP_TRACE_TAB(format, ...) {snprintf(__ANDROID_LOG_VPRINTF_BUFFER,__ANDROID_MAX_LOG_LINE_LENGTH__-1, format, ##__VA_ARGS__ ); printf("%-32.32s:%4d:TTRAC:%.4f:%s",__FILENAME__,__LINE__, gt(), __ANDROID_LOG_VPRINTF_BUFFER); } #define __ERROR(...) __LIBATSC3_TIMESTAMP_ERROR(__VA_ARGS__); #define __WARN(...) __LIBATSC3_TIMESTAMP_WARN(__VA_ARGS__); #define __INFO(...) __LIBATSC3_TIMESTAMP_INFO(__VA_ARGS__); #else #define __LIBATSC3_TIMESTAMP_ERROR(...) printf("%-24.24s:%4d:ERROR:%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_WARN(...) printf("%-24.24s:%4d:WARN :%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_INFO(...) printf("%-24.24s:%4d:INFO :%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_DUMP(...) printf("%-24.24s:%4d:DUMP :%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_DEBUG(...) printf("%-24.24s:%4d:DEBUG:%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_TRACE(...) printf("%-24.24s:%4d:TRACE:%.4f:",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __LIBATSC3_TIMESTAMP_TRACE_TAB(...) printf("%-24.24s\t%4d\tTRACE\t%.4f\t",__FILENAME__,__LINE__, gt()); printf(__VA_ARGS__); printf("%s%s","\r","\n"); #define __ERROR(...) __LIBATSC3_TIMESTAMP_ERROR(__VA_ARGS__); #define __WARN(...) __LIBATSC3_TIMESTAMP_WARN(__VA_ARGS__); #define __INFO(...) __LIBATSC3_TIMESTAMP_INFO(__VA_ARGS__); #endif #ifdef _ENABLE_DEBUG #define __DEBUG(...) __LIBATSC3_TIMESTAMP_DEBUG(__VA_ARGS__); #define __DEBUGF(...) printf("%s:%d:DEBUG: ","listener",__LINE__);printf(__VA_ARGS__);printf("%s%s","\r","\n") #define __DEBUGA(...) __PRINTF(__VA_ARGS__); #define __DEBUGN(...) __PRINTLN(__VA_ARGS__); #else #define __DEBUG(...) #define __DEBUGF(...) #define __DEBUGA(...) #define __DEBUGN(...) #endif #ifdef _ENABLE_TRACE #define __TRACE(...) __LIBATSC3_TIMESTAMP_TRACE(__VA_ARGS__); #else #define __TRACE(...) #endif #ifdef __cplusplus } #endif #endif /* ATSC3_LOGGING_EXTERNS_H_ */
ben-EDT/libatsc3
src/atsc3_pcre2_regex_utils.c
<reponame>ben-EDT/libatsc3 /* * atsc3_pcre2_regex_utils.c * * Created on: Jul 6, 2020 * Author: jjustman */ #include "atsc3_pcre2_regex_utils.h" int _PCRE2_REGEX_UTILS_INFO_ENABLED = 1; int _PCRE2_REGEX_UTILS_DEBUG_ENABLED = 0; int _PCRE2_REGEX_UTILS_TRACE_ENABLED = 0; //vector types impl ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(atsc3_preg2_regex_match_capture_group, atsc3_preg2_regex_match_capture); //impl to clear block_t reference: ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(atsc3_preg2_regex_match_capture); ATSC3_VECTOR_BUILDER_METHODS_IMPLEMENTATION(atsc3_pcre2_regex_match_capture_vector, atsc3_preg2_regex_match_capture_group); //impl to clear children ATSC3_VECTOR_BUILDER_METHODS_ITEM_FREE(atsc3_preg2_regex_match_capture_group); /* * jjustman-2020-07-13 - todo: support replacing via $1 ... $n reference capture group(s) directly with pcre2_substitute and pcre2_set_substitute_callout Substitution callouts int pcre2_set_substitute_callout(pcre2_match_context *mcontext, int (*callout_function)(pcre2_substitute_callout_block *, void *), void *callout_data); */ atsc3_pcre2_regex_context_t* atsc3_pcre2_regex_context_new(const char* pcre2_regex_pattern) { atsc3_pcre2_regex_context_t* atsc3_pcre2_regex_context = calloc(1, sizeof(atsc3_pcre2_regex_context_t)); atsc3_pcre2_regex_context->find_all = 1; //set /g by default atsc3_pcre2_regex_context->pattern = (PCRE2_SPTR) pcre2_regex_pattern; //compile our regex pattern atsc3_pcre2_regex_context->re = pcre2_compile(atsc3_pcre2_regex_context->pattern, PCRE2_ZERO_TERMINATED, /* indicates pattern is zero-terminated */ PCRE2_MULTILINE | PCRE2_DOTALL, /* default options */ &atsc3_pcre2_regex_context->errornumber, /* for error number */ &atsc3_pcre2_regex_context->erroroffset, /* for error offset */ NULL); /* use default compile context */ if (atsc3_pcre2_regex_context->re== NULL) { PCRE2_UCHAR buffer[256]; pcre2_get_error_message(atsc3_pcre2_regex_context->errornumber, buffer, sizeof(buffer)); __PCRE2_REGEX_UTILS_ERROR("PCRE2 compilation failed at offset %d: %s", (int)atsc3_pcre2_regex_context->erroroffset, buffer); goto error; } //setup the match_data block for right size of capture groups atsc3_pcre2_regex_context->match_data = pcre2_match_data_create_from_pattern(atsc3_pcre2_regex_context->re, NULL); return atsc3_pcre2_regex_context; error: if(atsc3_pcre2_regex_context) { atsc3_pcre2_regex_context_free(&atsc3_pcre2_regex_context); } if(atsc3_pcre2_regex_context->re) { pcre2_code_free(atsc3_pcre2_regex_context->re); atsc3_pcre2_regex_context->re = NULL; } return NULL; } void atsc3_preg2_regex_extract_and_assign_named_capture_groups(atsc3_pcre2_regex_context_t *atsc3_pcre2_regex_context, atsc3_preg2_regex_match_capture_group_t *atsc3_preg2_regex_match_capture_group, PCRE2_SPTR subject, PCRE2_SIZE subject_length) { pcre2_pattern_info(atsc3_pcre2_regex_context->re, PCRE2_INFO_NAMECOUNT, &atsc3_pcre2_regex_context->namecount); /* do we have any named capture groups to process?*/ if (atsc3_pcre2_regex_context->namecount == 0) { __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: atsc3_pcre2_regex_context: %p - No named substrings", atsc3_pcre2_regex_context); return; } else { PCRE2_SPTR tabptr; __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: atsc3_pcre2_regex_context: %p - have %d namecount captures", atsc3_pcre2_regex_context, atsc3_pcre2_regex_context->namecount); /* Before we can access the substrings, we must extract the table for translating names to numbers, and the size of each entry in the table. */ (void)pcre2_pattern_info( atsc3_pcre2_regex_context->re, /* the compiled pattern */ PCRE2_INFO_NAMETABLE, /* address of the table */ &atsc3_pcre2_regex_context->name_table); /* where to put the answer */ (void)pcre2_pattern_info( atsc3_pcre2_regex_context->re, /* the compiled pattern */ PCRE2_INFO_NAMEENTRYSIZE, /* size of each entry in the table */ &atsc3_pcre2_regex_context->name_entry_size); /* where to put the answer */ // Now we can scan the table and, for each entry, print the number, the name, // and the substring itself. In the 8-bit library the number is held in two // bytes, most significant first. tabptr = atsc3_pcre2_regex_context->name_table; for (int i = 0; i < atsc3_pcre2_regex_context->namecount; i++) { atsc3_preg2_regex_match_capture_t* atsc3_preg2_regex_match_capture = NULL; //use n as the actual pcre2_regex_match capture_id, as our namecount will be sparse if not every capture group is named... int n = (tabptr[0] << 8) | tabptr[1]; for(int j = 0; j < atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.count && !atsc3_preg2_regex_match_capture; j++) { atsc3_preg2_regex_match_capture = atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.data[j]; if(atsc3_preg2_regex_match_capture && atsc3_preg2_regex_match_capture->capture_reference_id != n) { atsc3_preg2_regex_match_capture = NULL; continue; } //we have a match based upon capture_id, sanity check our match_capture as needed //example output looks like: (1) repId: Video1_1 // (n) (name_entry_sz) (tabptr+2): (ovector[2*n+1]-ovector[2*n]) (subject+ovector[2*n] - already captured in atsc3_preg2_regex_match_capture->substring) //sanity check PCRE2_SIZE substring_length = atsc3_pcre2_regex_context->ovector[2*i+1] - atsc3_pcre2_regex_context->ovector[2*i]; if(atsc3_preg2_regex_match_capture->substring && !strncmp((const char*)(subject + atsc3_pcre2_regex_context->ovector[2*n]), (const char*)block_Get(atsc3_preg2_regex_match_capture->substring), __MIN(substring_length, strlen((const char*)block_Get(atsc3_preg2_regex_match_capture->substring))))) { atsc3_preg2_regex_match_capture->capture_name = strdup((const char*)(tabptr + 2)); __PCRE2_REGEX_UTILS_DEBUG("atsc3_pcre2_regex_match: assigning named capture: %s to capture_id: %d, substring value: %s", atsc3_preg2_regex_match_capture->capture_name, atsc3_preg2_regex_match_capture->capture_reference_id, block_Get(atsc3_preg2_regex_match_capture->substring)); break; } else { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: unable to assign named_match: id: %d, atsc3_preg2_regex_match_capture->capture_reference_id: %d, capture_name: %s, capture_val: %s, atsc3_preg2_regex_match_capture->substring: %s", n, atsc3_preg2_regex_match_capture->capture_reference_id, tabptr + 2, subject + atsc3_pcre2_regex_context->ovector[2*n], block_Get(atsc3_preg2_regex_match_capture->substring)); atsc3_preg2_regex_match_capture = NULL; continue; } } //if we get here without an atsc3_preg2_regex_match_capture, then we wern't able match this named capture up if(!atsc3_preg2_regex_match_capture) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: unable to find assigned named_match: id: %d %*s: %.*s, atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.count is only: %d!", n, atsc3_pcre2_regex_context->name_entry_size - 3, tabptr + 2, (int)(atsc3_pcre2_regex_context->ovector[2*n+1] - atsc3_pcre2_regex_context->ovector[2*n]), subject + atsc3_pcre2_regex_context->ovector[2*n], atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.count); } tabptr += atsc3_pcre2_regex_context->name_entry_size; } } } atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match(atsc3_pcre2_regex_context_t* atsc3_pcre2_regex_context, block_t* subject_block) { if(!atsc3_pcre2_regex_context || !atsc3_pcre2_regex_context->match_data) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: atsc3_pcre2_regex_context (or match_data) is null!"); return NULL; } if(!subject_block->p_size) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: subject_block->p_size is 0!"); return NULL; } int capture_group_id = 0; atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match_capture_vector = atsc3_pcre2_regex_match_capture_vector_new_from_block_t(subject_block); //placeholder handles atsc3_preg2_regex_match_capture_group_t* atsc3_preg2_regex_match_capture_group = NULL; atsc3_preg2_regex_match_capture_t* atsc3_preg2_regex_match_capture = NULL; int rc; PCRE2_SPTR subject = NULL; /* the appropriate width (in this case, 8 bits). */ PCRE2_SIZE subject_length; subject = (PCRE2_SPTR) subject_block->p_buffer; subject_length = (PCRE2_SIZE)strlen((char *)subject); //jjustman-2020-07-13 - todo, change to subject_block->p_size? rc = pcre2_match(atsc3_pcre2_regex_context->re, subject, subject_length, 0, /* start at offset 0 in the subject */ 0, /* default options */ atsc3_pcre2_regex_context->match_data, /* block for storing the result */ NULL); /* use default match context */ /* Matching failed: handle error cases */ if (rc < 0) { switch(rc) { case PCRE2_ERROR_NOMATCH: __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: no match for pattern: %s, with data: %s", atsc3_pcre2_regex_context->pattern, subject_block->p_buffer); break; /* Handle other special cases if you like */ default: __PCRE2_REGEX_UTILS_INFO("atsc3_pcre2_regex_match: Matching error %d", rc); break; } goto error; } /* Match succeded. Get a pointer to the output vector, where string offsets are stored. */ atsc3_pcre2_regex_context->ovector = pcre2_get_ovector_pointer(atsc3_pcre2_regex_context->match_data); __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: Match succeeded at offset %d ", (int)atsc3_pcre2_regex_context->ovector[0]); /************************************************************************* * We have found the first match within the subject string. If the output * * vector wasn't big enough, say so. Then output any substrings that were * * captured. * *************************************************************************/ /* The output vector wasn't big enough. This should not happen, because we used pcre2_match_data_create_from_pattern() above. */ if (rc == 0) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: ovector was not big enough for all the captured substrings"); //jjustman-2020-07-13 todo? goto error; goto error; } /* We must guard against patterns such as /(?=.\K)/ that use \K in an assertion to set the start of a match later than its end. In this demonstration program, we just detect this case and give up. */ if (atsc3_pcre2_regex_context->ovector[0] > atsc3_pcre2_regex_context->ovector[1]) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: \\K was used in an assertion to set the match start after its end." "From end to start the match was: %.*s", (int)(atsc3_pcre2_regex_context->ovector[0] - atsc3_pcre2_regex_context->ovector[1]), (char *)(subject + atsc3_pcre2_regex_context->ovector[1])); goto error; } /* Show substrings stored in the output vector by number. Obviously, in a real application you might want to do things other than print them. */ //jjustman-2020-07-14 - TODO: fix copy/paste below for Nth capture group atsc3_preg2_regex_match_capture_group = atsc3_preg2_regex_match_capture_group_new(); atsc3_preg2_regex_match_capture_group->capture_group_id = capture_group_id++; atsc3_pcre2_regex_match_capture_vector_add_atsc3_preg2_regex_match_capture_group(atsc3_pcre2_regex_match_capture_vector, atsc3_preg2_regex_match_capture_group); __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: first match capture group dump, rc: %d", rc); for (int i = 0; i < rc; i++) { atsc3_preg2_regex_match_capture = atsc3_preg2_regex_match_capture_new(); atsc3_preg2_regex_match_capture->capture_reference_id = i; atsc3_preg2_regex_match_capture->match_start = atsc3_pcre2_regex_context->ovector[2*i]; atsc3_preg2_regex_match_capture->match_end = atsc3_pcre2_regex_context->ovector[2*i+1]; PCRE2_SPTR substring_start = subject + atsc3_pcre2_regex_context->ovector[2*i]; PCRE2_SIZE substring_length = atsc3_pcre2_regex_context->ovector[2*i+1] - atsc3_pcre2_regex_context->ovector[2*i]; //use our local subject block_t ref atsc3_preg2_regex_match_capture->pcre_substring_start = block_Get(atsc3_pcre2_regex_match_capture_vector->subject_block) + atsc3_pcre2_regex_context->ovector[2*i]; atsc3_preg2_regex_match_capture->pcre_substring_length = substring_length; //todo - jjustman-2020-07-14 - refactor this out to common pattern for promoting pcre non-null terminated substrings to block_t null terminated strings atsc3_preg2_regex_match_capture->substring = block_Alloc(substring_length + 1); block_Write(atsc3_preg2_regex_match_capture->substring, atsc3_preg2_regex_match_capture->pcre_substring_start, substring_length); block_Rewind(atsc3_preg2_regex_match_capture->substring); atsc3_preg2_regex_match_capture_group_add_atsc3_preg2_regex_match_capture(atsc3_preg2_regex_match_capture_group, atsc3_preg2_regex_match_capture); __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: %2d (s: %zu, e: %zu): %.*s", i, atsc3_pcre2_regex_context->ovector[2*i], atsc3_pcre2_regex_context->ovector[2*i+1], (int)substring_length, (char *)substring_start); } atsc3_preg2_regex_extract_and_assign_named_capture_groups(atsc3_pcre2_regex_context, atsc3_preg2_regex_match_capture_group, subject, subject_length); // /g is set by default, otherwise return just this single match capture group if (!atsc3_pcre2_regex_context->find_all) { pcre2_match_data_free(atsc3_pcre2_regex_context->match_data); /* Release the memory that was used */ pcre2_code_free(atsc3_pcre2_regex_context->re); /* for the match data and the pattern. */ return atsc3_pcre2_regex_match_capture_vector; } /* Before running the loop, check for UTF-8 and whether CRLF is a valid newline sequence. First, find the options with which the regex was compiled and extract the UTF state. */ (void)pcre2_pattern_info(atsc3_pcre2_regex_context->re, PCRE2_INFO_ALLOPTIONS, &atsc3_pcre2_regex_context->option_bits); atsc3_pcre2_regex_context->utf8 = (atsc3_pcre2_regex_context->option_bits & PCRE2_UTF) != 0; /* Now find the newline convention and see whether CRLF is a valid newline sequence. */ (void)pcre2_pattern_info(atsc3_pcre2_regex_context->re, PCRE2_INFO_NEWLINE, &atsc3_pcre2_regex_context->newline); atsc3_pcre2_regex_context->crlf_is_newline = atsc3_pcre2_regex_context->newline == PCRE2_NEWLINE_ANY || atsc3_pcre2_regex_context->newline == PCRE2_NEWLINE_CRLF || atsc3_pcre2_regex_context->newline == PCRE2_NEWLINE_ANYCRLF; /* Loop for second and subsequent matches */ for (;;) { uint32_t options = 0; /* Normally no options */ PCRE2_SIZE start_offset = atsc3_pcre2_regex_context->ovector[1]; /* Start at end of previous match */ /* If the previous match was for an empty string, we are finished if we are at the end of the subject. Otherwise, arrange to run another match at the same point to see if a non-empty match can be found. */ if (atsc3_pcre2_regex_context->ovector[0] == atsc3_pcre2_regex_context->ovector[1]) { if (atsc3_pcre2_regex_context->ovector[0] == subject_length) { break; } options = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED; } else { /* If the previous match was not an empty string, there is one tricky case to consider. If a pattern contains \K within a lookbehind assertion at the start, the end of the matched string can be at the offset where the match started. Without special action, this leads to a loop that keeps on matching the same substring. We must detect this case and arrange to move the start on by one character. The pcre2_get_startchar() function returns the starting offset that was passed to pcre2_match(). */ PCRE2_SIZE startchar = pcre2_get_startchar(atsc3_pcre2_regex_context->match_data); if (start_offset <= startchar) { if (startchar >= subject_length) { break; /* Reached end of subject. */ } start_offset = startchar + 1; /* Advance by one character. */ if (atsc3_pcre2_regex_context->utf8) { /* if UTF-8, it may be more than one code unit. */ for (; start_offset < subject_length; start_offset++) { if ((subject[start_offset] & 0xc0) != 0x80) { break; } } } } } /* Run the next matching operation */ rc = pcre2_match(atsc3_pcre2_regex_context->re, subject, subject_length, /* the length of the subject */ start_offset, /* starting offset in the subject */ options, /* options */ atsc3_pcre2_regex_context->match_data, /* block for storing the result */ NULL); /* use default match context */ /* This time, a result of NOMATCH isn't an error. If the value in "options" is zero, it just means we have found all possible matches, so the loop ends. Otherwise, it means we have failed to find a non-empty-string match at a point where there was a previous empty-string match. In this case, we do what Perl does: advance the matching position by one character, and continue. We do this by setting the "end of previous match" offset, because that is picked up at the top of the loop as the point at which to start again. There are two complications: (a) When CRLF is a valid newline sequence, and the current position is just before it, advance by an extra byte. (b) Otherwise we must ensure that we skip an entire UTF character if we are in UTF mode. */ if (rc == PCRE2_ERROR_NOMATCH) { if (options == 0) { break; /* All matches found */ } atsc3_pcre2_regex_context->ovector[1] = start_offset + 1; /* Advance one code unit */ if (atsc3_pcre2_regex_context->crlf_is_newline && /* If CRLF is a newline & */ start_offset < subject_length - 1 && /* we are at CRLF, */ subject[start_offset] == '\r' && subject[start_offset + 1] == '\n') { /* Advance by one more. */ atsc3_pcre2_regex_context->ovector[1] += 1; } else if (atsc3_pcre2_regex_context->utf8) { /* Otherwise, ensure we advance a whole UTF-8 */ while (atsc3_pcre2_regex_context->ovector[1] < subject_length) { /* character. */ if ((subject[atsc3_pcre2_regex_context->ovector[1]] & 0xc0) != 0x80) { break; } atsc3_pcre2_regex_context->ovector[1] += 1; } } continue; /* Go round the loop again */ } /* Other matching errors are not recoverable. */ if (rc < 0) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: Matching error %d", rc); goto error; } /* Match succeded */ __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: atsc3_pcre2_regex_context: %p, Match succeeded again at offset: %d", atsc3_pcre2_regex_context, (int)atsc3_pcre2_regex_context->ovector[0]); /* The match succeeded, but the output vector wasn't big enough. This should not happen. */ if (rc == 0) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: atsc3_pcre2_regex_context: %p, ovector was not big enough for all the captured substrings, rc: %d", atsc3_pcre2_regex_context, rc); } /* We must guard against patterns such as /(?=.\K)/ that use \K in an assertion to set the start of a match later than its end. In this demonstration program, we just detect this case and give up. */ if (atsc3_pcre2_regex_context->ovector[0] > atsc3_pcre2_regex_context->ovector[1]) { __PCRE2_REGEX_UTILS_ERROR("atsc3_pcre2_regex_match: \\K was used in an assertion to set the match start after its end." "From end to start the match was: %.*s", (int)(atsc3_pcre2_regex_context->ovector[0] - atsc3_pcre2_regex_context->ovector[1]), (char *)(subject + atsc3_pcre2_regex_context->ovector[1])); goto error; } /* As before, show substrings stored in the output vector by number, and then also any named substrings. */ //jjustman-2020-07-14 - TODO: fix copy/paste below for Nth capture group atsc3_preg2_regex_match_capture_group = atsc3_preg2_regex_match_capture_group_new(); atsc3_preg2_regex_match_capture_group->capture_group_id = capture_group_id++; atsc3_pcre2_regex_match_capture_vector_add_atsc3_preg2_regex_match_capture_group(atsc3_pcre2_regex_match_capture_vector, atsc3_preg2_regex_match_capture_group); for (int i = 0; i < rc; i++) { atsc3_preg2_regex_match_capture = atsc3_preg2_regex_match_capture_new(); atsc3_preg2_regex_match_capture->capture_reference_id = i; atsc3_preg2_regex_match_capture->match_start = atsc3_pcre2_regex_context->ovector[2*i]; atsc3_preg2_regex_match_capture->match_end = atsc3_pcre2_regex_context->ovector[2*i+1]; PCRE2_SPTR substring_start = subject + atsc3_pcre2_regex_context->ovector[2*i]; size_t substring_length = atsc3_pcre2_regex_context->ovector[2*i+1] - atsc3_pcre2_regex_context->ovector[2*i]; //use our local subject block_t ref atsc3_preg2_regex_match_capture->pcre_substring_start = block_Get(atsc3_pcre2_regex_match_capture_vector->subject_block) + atsc3_pcre2_regex_context->ovector[2*i]; atsc3_preg2_regex_match_capture->pcre_substring_length = substring_length; //todo - jjustman-2020-07-14 - refactor this out to common pattern for promoting pcre non-null terminated substrings to block_t null terminated strings atsc3_preg2_regex_match_capture->substring = block_Alloc(substring_length + 1); block_Write(atsc3_preg2_regex_match_capture->substring, atsc3_preg2_regex_match_capture->pcre_substring_start, substring_length); block_Rewind(atsc3_preg2_regex_match_capture->substring); atsc3_preg2_regex_match_capture_group_add_atsc3_preg2_regex_match_capture(atsc3_preg2_regex_match_capture_group, atsc3_preg2_regex_match_capture); __PCRE2_REGEX_UTILS_TRACE("atsc3_pcre2_regex_match: %2d (s: %zu, e: %zu): %.*s", i, atsc3_pcre2_regex_context->ovector[2*i], atsc3_pcre2_regex_context->ovector[2*i+1], (int)substring_length, (char *)substring_start); } atsc3_preg2_regex_extract_and_assign_named_capture_groups(atsc3_pcre2_regex_context, atsc3_preg2_regex_match_capture_group, subject, subject_length); } /* End of loop to find second and subsequent matches */ complete: __PCRE2_REGEX_UTILS_DEBUG("atsc3_pcre2_regex_match: returning match capture vector: %p, capture groups: %d", atsc3_pcre2_regex_match_capture_vector, atsc3_pcre2_regex_match_capture_vector->atsc3_preg2_regex_match_capture_group_v.count); //atsc3_pcre2_regex_match_capture_vector return atsc3_pcre2_regex_match_capture_vector; error: if(atsc3_pcre2_regex_context->match_data) { pcre2_match_data_free(atsc3_pcre2_regex_context->match_data); /* Release memory used for the match */ atsc3_pcre2_regex_context->match_data = NULL; } if(atsc3_pcre2_regex_context->re) { pcre2_code_free(atsc3_pcre2_regex_context->re); /* data and the compiled pattern. */ atsc3_pcre2_regex_context->re = NULL; } if(atsc3_pcre2_regex_match_capture_vector) { atsc3_pcre2_regex_match_capture_vector_free(&atsc3_pcre2_regex_match_capture_vector); } return NULL; } //jjustman-2020-07-14 - todo: macro _new and _free for ATSC3_ALLOC() with chained VECTOR_BUILDER destructors.. atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match_capture_vector_new_from_block_t(block_t* subject_block_to_copy) { atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match_captures = calloc(1, sizeof(atsc3_pcre2_regex_match_capture_vector_t)); atsc3_pcre2_regex_match_captures->subject_block = block_Duplicate(subject_block_to_copy); block_Rewind(atsc3_pcre2_regex_match_captures->subject_block); return atsc3_pcre2_regex_match_captures; } void atsc3_pcre2_regex_match_capture_vector_dump(atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match_capture_vector) { __PCRE2_REGEX_UTILS_DEBUG("atsc3_pcre2_regex_match_capture_vector: %p", atsc3_pcre2_regex_match_capture_vector); __PCRE2_REGEX_UTILS_DEBUG(" subject_block (size: %d):\n%s", atsc3_pcre2_regex_match_capture_vector->subject_block->p_size, atsc3_pcre2_regex_match_capture_vector->subject_block->p_buffer); __PCRE2_REGEX_UTILS_DEBUG(" ---"); __PCRE2_REGEX_UTILS_DEBUG(" capture group count: %d", atsc3_pcre2_regex_match_capture_vector->atsc3_preg2_regex_match_capture_group_v.count); __PCRE2_REGEX_UTILS_DEBUG(" ---"); for(int i = 0; i < atsc3_pcre2_regex_match_capture_vector->atsc3_preg2_regex_match_capture_group_v.count; i++) { atsc3_preg2_regex_match_capture_group_t* atsc3_preg2_regex_match_capture_group = atsc3_pcre2_regex_match_capture_vector->atsc3_preg2_regex_match_capture_group_v.data[i]; __PCRE2_REGEX_UTILS_DEBUG(" capture group: %d, contains %d references", atsc3_preg2_regex_match_capture_group->capture_group_id, atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.count); for(int j = 0; j < atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.count; j++) { atsc3_preg2_regex_match_capture_t* atsc3_preg2_regex_match_capture = atsc3_preg2_regex_match_capture_group->atsc3_preg2_regex_match_capture_v.data[j]; __PCRE2_REGEX_UTILS_DEBUG(" ref: %d (start: %zu, end: %zu, length: %d), value:\n%s", atsc3_preg2_regex_match_capture->capture_reference_id, atsc3_preg2_regex_match_capture->match_start, atsc3_preg2_regex_match_capture->match_end, atsc3_preg2_regex_match_capture->substring->p_size, block_Get(atsc3_preg2_regex_match_capture->substring)); } } } void atsc3_preg2_regex_match_capture_free(atsc3_preg2_regex_match_capture_t** atsc3_preg2_regex_match_capture_p) { if(atsc3_preg2_regex_match_capture_p) { atsc3_preg2_regex_match_capture_t* atsc3_preg2_regex_match_capture = *atsc3_preg2_regex_match_capture_p; if(atsc3_preg2_regex_match_capture) { if(atsc3_preg2_regex_match_capture->capture_name) { freeclean((void**)&atsc3_preg2_regex_match_capture->capture_name); } if(atsc3_preg2_regex_match_capture->substring) { block_Destroy(&atsc3_preg2_regex_match_capture->substring); } free(atsc3_preg2_regex_match_capture); atsc3_preg2_regex_match_capture = NULL; } *atsc3_preg2_regex_match_capture_p = NULL; } } void atsc3_preg2_regex_match_capture_group_free(atsc3_preg2_regex_match_capture_group_t** atsc3_preg2_regex_match_capture_group_p) { if(atsc3_preg2_regex_match_capture_group_p) { atsc3_preg2_regex_match_capture_group_t* atsc3_preg2_regex_match_capture_group = *atsc3_preg2_regex_match_capture_group_p; if(atsc3_preg2_regex_match_capture_group) { atsc3_preg2_regex_match_capture_group_free_atsc3_preg2_regex_match_capture(atsc3_preg2_regex_match_capture_group); free(atsc3_preg2_regex_match_capture_group); atsc3_preg2_regex_match_capture_group = NULL; } *atsc3_preg2_regex_match_capture_group_p = NULL; } } void atsc3_pcre2_regex_match_capture_vector_free(atsc3_pcre2_regex_match_capture_vector_t** atsc3_pcre2_regex_match_captures_p) { if(atsc3_pcre2_regex_match_captures_p) { atsc3_pcre2_regex_match_capture_vector_t* atsc3_pcre2_regex_match_captures = *atsc3_pcre2_regex_match_captures_p; if(atsc3_pcre2_regex_match_captures) { if(atsc3_pcre2_regex_match_captures->subject_block) { block_Destroy(&atsc3_pcre2_regex_match_captures->subject_block); } atsc3_pcre2_regex_match_capture_vector_free_atsc3_preg2_regex_match_capture_group(atsc3_pcre2_regex_match_captures); free(atsc3_pcre2_regex_match_captures); atsc3_pcre2_regex_match_captures = NULL; } *atsc3_pcre2_regex_match_captures_p = NULL; } } void atsc3_pcre2_regex_context_free(atsc3_pcre2_regex_context_t** atsc3_pcre2_regex_context_p) { if(atsc3_pcre2_regex_context_p) { atsc3_pcre2_regex_context_t* atsc3_pcre2_regex_context = *atsc3_pcre2_regex_context_p; if(atsc3_pcre2_regex_context) { //TODO: jjustman-2020-07-13 - clean up other members here //boilerplate if(atsc3_pcre2_regex_context->match_data) { pcre2_match_data_free(atsc3_pcre2_regex_context->match_data); /* Release memory used for the match */ atsc3_pcre2_regex_context->match_data = NULL; } if(atsc3_pcre2_regex_context->re) { pcre2_code_free_8(atsc3_pcre2_regex_context->re); atsc3_pcre2_regex_context->re = NULL; } free(atsc3_pcre2_regex_context); atsc3_pcre2_regex_context = NULL; } *atsc3_pcre2_regex_context_p = NULL; } } /* * * subject = (PCRE2_SPTR) block_mpd->p_buffer; subject_length = (PCRE2_SIZE)strlen((char *)subject); */
ben-EDT/libatsc3
src/atsc3_ntp_utils.h
<gh_stars>10-100 /* * atsc3_mmtp_ntp32_to_pts.h * * Created on: Jan 8, 2019 * Author: jjustman */ #ifndef MODULES_DEMUX_MMT_MMTP_NTP32_TO_PTS_H_ #define MODULES_DEMUX_MMT_MMTP_NTP32_TO_PTS_H_ #include "atsc3_utils.h" #include <time.h> #include <stdio.h> /** * convert ntp "short-format" packet time into a future re-clocked pts * short-format is: * * int16_t seconds * int16_t s_fragment * * seconds rolls over at 65535 from every ntp epoc, so we need to un-bias this when computing a future offset * * instead */ #define REBASE_PTS_OFFSET 0 #if defined (__cplusplus) extern "C" { #endif void compute_ntp32_to_seconds_microseconds(uint32_t timestamp, uint16_t *seconds, uint16_t *microseconds); void compute_ntp64_to_seconds_microseconds(uint64_t timestamp, uint32_t *seconds, uint32_t *microseconds); uint32_t ntp32_compute_from_seconds_microseconds(uint16_t seconds, uint16_t microseconds); uint64_t ntp64_compute_from_seconds_microseconds(uint16_t seconds, uint16_t microseconds); uint64_t compute_relative_ntp32_pts(uint64_t first_pts, uint16_t mmtp_timestamp_s, uint16_t mmtp_timestamp_microseconds); int64_t rebase_now_with_ntp32(uint16_t mmtp_timestamp_s, uint16_t mmtp_timestamp_microseconds); #if defined (__cplusplus) } #endif #endif /* MODULES_DEMUX_MMT_MMTP_NTP32_TO_PTS_H_ */
ben-EDT/libatsc3
src/atsc3_core_service_player_bridge.h
// // Created by <NAME> on 2019-09-27. // #ifndef __JJ_PHY_MMT_PLAYER_BRIDGE_DISABLED #include <string> #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <sys/stat.h> #include <time.h> #include <signal.h> #include <limits.h> #ifndef _WIN32 #include <sys/ioctl.h> #include <ftw.h> #endif #include <mutex> #include <set> using namespace std; #ifndef LIBATSC3_ATSC3CORESERVICEPLAYERBRIDGE_H #define LIBATSC3_ATSC3CORESERVICEPLAYERBRIDGE_H #include "atsc3_utils.h" #include "atsc3_logging_externs.h" #include "atsc3_listener_udp.h" #include "atsc3_alp_types.h" #include "atsc3_alc_rx.h" #include "atsc3_lls_types.h" #include "atsc3_sl_tlv_demod_type.h" #include "atsc3_lls.h" #include "atsc3_lls_slt_parser.h" #include "atsc3_lls_sls_monitor_output_buffer_utils.h" #include "atsc3_lls_types.h" #include "atsc3_mmtp_packet_types.h" #include "atsc3_mmtp_parser.h" #include "atsc3_ntp_utils.h" #include "atsc3_mmt_mpu_utils.h" #include "atsc3_mmt_context_mfu_depacketizer.h" #include "atsc3_hevc_nal_extractor.h" #include "atsc3_lls_alc_utils.h" #include "atsc3_alc_rx.h" #include "atsc3_alp_types.h" #include "atsc3_mmt_mfu_context_callbacks_default_jni.h" //runtime app interface includes (e.g. I/F for android, etc) #include "application/IAtsc3NdkApplicationBridge.h" #include "phy/IAtsc3NdkPHYBridge.h" #include "phy/IAtsc3NdkPHYClient.h" //c++ linkage methods string atsc3_route_service_context_temp_folder_name(int service_id); string atsc3_ndk_cache_temp_folder_path_get(int service_id); #if defined (__cplusplus) extern "C" { #endif //methods void atsc3_core_service_application_bridge_init(IAtsc3NdkApplicationBridge* atsc3NdkApplicationBridge); void atsc3_core_service_application_bridge_reset_context(); IAtsc3NdkApplicationBridge* atsc3_ndk_application_bridge_get_instance(); void atsc3_core_service_phy_bridge_init(IAtsc3NdkPHYBridge* atsc3NdkPHYBridge); IAtsc3NdkPHYBridge* atsc3_ndk_phy_bridge_get_instance(); //jjustman-2020-08-18 - signature match for typedef void(*atsc3_phy_rx_udp_packet_process_callback_f)(uint8_t plp_num, block_t* block); void atsc3_core_service_bridge_process_packet_from_plp_and_block(uint8_t plp_num, block_t* block); void atsc3_core_service_bridge_process_packet_phy(block_t* packet); //change SLT service and wire up a single montior atsc3_lls_slt_service_t* atsc3_core_service_player_bridge_set_single_monitor_a331_service_id(int service_id); //add additional alc monitor service_id's for supplimentary MMT or ROUTE flows atsc3_lls_slt_service_t* atsc3_core_service_player_bridge_add_monitor_a331_service_id(int service_id); atsc3_lls_slt_service_t* atsc3_core_service_player_bridge_remove_monitor_a331_service_id(int service_id); //jjustman-2021-01-21 - friend helper from atsc3NdkApplicationBridge when setting a new service or adding an additional monitor // NOTE: final update of listened PLP's needs to happen after this call with returned vector, e.g. // Atsc3NdkApplicationBridge_ptr->atsc3_phy_notify_plp_selection_changed(plps_to_listen); // we return a 'sparse' list (e.g. only set plps we want to listen to), this allows us to 'decorate' as needed... if phy needs special markers to ignore unused slots, e.g. 0xFF vector<uint8_t> atsc3_phy_build_plp_listeners_from_lls_slt_monitor(lls_slt_monitor_t* lls_slt_monitor); //TODO: wire up ROUTE/ALC and MBMS/FDT event callback hooks for close_object emission (including delivery metrics w.r.t ALC DU loss) //jjustman-2021-01-21 - acquire our context_mutex before using lls_slt_monitor or lls_sls_alc_monitor //use with RAII style scoping for acquisition/release, e.g. /* * void atsc3_...() { * * //acquire RAII block scope for mutex boundary * { * lock_guard<recursive_mutex> atsc3_core_service_player_bridge_context_mutex_local(atsc3_core_service_player_bridge_context_mutex); * * ... * } * //mutex is implicity released * * ... * * return; * } */ recursive_mutex& atsc3_core_service_player_bridge_get_context_mutex(); lls_slt_monitor_t* atsc3_core_service_player_bridge_get_lls_slt_montior(); lls_sls_alc_monitor_t* atsc3_lls_sls_alc_monitor_get_from_service_id(int service_id); //end mutex context accessors //ALC/ROUTE: use case: parse out the atsc3_mbms_metadata_envelope to get MPD from metadataURI atsc3_sls_metadata_fragments_t* atsc3_slt_alc_get_sls_metadata_fragments_from_monitor_service_id(int service_id); //ALC/ROUTE: use case: get the app-based/esg service corresponding efdt atsc3_fdt_file content_location value atsc3_route_s_tsid_t* atsc3_slt_alc_get_sls_route_s_tsid_from_monitor_service_id(int service_id); //free our old atsc3_link_mapping_table_t* if returned atsc3_link_mapping_table_t* atsc3_phy_jni_bridge_notify_link_mapping_table(atsc3_link_mapping_table_t* atsc3_link_mapping_table_pending); int atsc3_ndk_cache_temp_folder_purge(char *path); void atsc3_lls_sls_alc_on_object_close_flag_s_tsid_content_location_ndk(uint16_t service_id, uint32_t tsi, uint32_t toi, char* s_tsid_content_location, char* s_tsid_content_type, char* cache_file_path); void atsc3_lls_sls_alc_on_package_extract_completed_callback_ndk(atsc3_route_package_extracted_envelope_metadata_and_payload_t* atsc3_route_package_extracted_envelope_metadata_and_payload_t); void atsc3_lls_sls_alc_on_route_mpd_patched_ndk(uint16_t service_id); //#1569 void atsc3_sls_on_held_trigger_received_callback_impl(uint16_t service_id, block_t* held_payload); /* * * internally defined _f callback handlers wired up in: atsc3_core_service_player_bridge_init lls_slt_monitor->atsc3_lls_on_sls_table_present_callback = &atsc3_lls_on_sls_table_present_ndk; atsc3_mmt_mfu_context->atsc3_mmt_mpu_mfu_on_sample_complete = &atsc3_mmt_mpu_mfu_on_sample_complete_ndk; atsc3_mmt_mfu_context->atsc3_mmt_mpu_mfu_on_sample_corrupt = &atsc3_mmt_mpu_mfu_on_sample_corrupt_ndk; //todo: search thru NAL's as needed here and discard anything that intra-NAL.. atsc3_mmt_mfu_context->atsc3_mmt_mpu_mfu_on_sample_corrupt_mmthsample_header = &atsc3_mmt_mpu_mfu_on_sample_corrupt_mmthsample_header_ndk; atsc3_mmt_mfu_context->atsc3_mmt_mpu_mfu_on_sample_missing = &atsc3_mmt_mpu_mfu_on_sample_missing_ndk; atsc3_mmt_mfu_context->atsc3_mmt_signalling_information_on_video_packet_id_with_mpu_timestamp_descriptor = &atsc3_mmt_signalling_information_on_video_packet_id_with_mpu_timestamp_descriptor_ndk; atsc3_mmt_mfu_context->atsc3_mmt_signalling_information_on_audio_packet_id_with_mpu_timestamp_descriptor = &atsc3_mmt_signalling_information_on_audio_packet_id_with_mpu_timestamp_descriptor_ndk; atsc3_mmt_mfu_context->atsc3_mmt_signalling_information_on_stpp_packet_id_with_mpu_timestamp_descriptor = &atsc3_mmt_signalling_information_on_stpp_packet_id_with_mpu_timestamp_descriptor_ndk; //extract out one trun sampleduration for essence timing atsc3_mmt_mfu_context->atsc3_mmt_mpu_on_sequence_movie_fragment_metadata_present = &atsc3_mmt_mpu_on_sequence_movie_fragment_metadata_present_ndk; void atsc3_lls_on_sls_table_present_ndk(lls_table_t* lls_table); void atsc3_mmt_mpu_on_sequence_mpu_metadata_present_ndk(uint16_t packet_id, uint32_t mpu_sequence_number, block_t* mmt_mpu_metadata); */ void atsc3_lls_on_sls_table_present_ndk(lls_table_t* lls_table); void atsc3_lls_on_aeat_table_present_ndk(lls_table_t* lls_table); bool atsc3_mmt_signalling_information_on_routecomponent_message_present_ndk(atsc3_mmt_mfu_context_t* atsc3_mmt_mfu_context, mmt_atsc3_route_component_t* mmt_atsc3_route_component); void atsc3_mmt_signalling_information_on_held_message_present_ndk(atsc3_mmt_mfu_context_t* atsc3_mmt_mfu_context, mmt_atsc3_held_message_t* mmt_atsc3_held_message); #define __ATSC3_CORE_SERVICE_PLAYER_BRIDGE_ERROR(...) __LIBATSC3_TIMESTAMP_ERROR(__VA_ARGS__); #define __ATSC3_CORE_SERVICE_PLAYER_BRIDGE_WARN(...) __LIBATSC3_TIMESTAMP_WARN(__VA_ARGS__); #define __ATSC3_CORE_SERVICE_PLAYER_BRIDGE_INFO(...) if(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_INFO_ENABLED) { __LIBATSC3_TIMESTAMP_INFO(__VA_ARGS__); } #define __ATSC3_CORE_SERVICE_PLAYER_BRIDGE_DEBUG(...) if(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_DEBUG_ENABLED) { __LIBATSC3_TIMESTAMP_DEBUG(__VA_ARGS__); } #define __ATSC3_CORE_SERVICE_PLAYER_BRIDGE_TRACE(...) if(_ATSC3_CORE_SERVICE_PLAYER_BRIDGE_TRACE_ENABLED) { __LIBATSC3_TIMESTAMP_TRACE(__VA_ARGS__); } #if defined (__cplusplus) } #endif #endif //LIBATSC3_ATSC3CORESERVICEPLAYERBRIDGE_H #endif
Sensirion/embedded-i2c-sen5x
tests/sensirion_test_setup.h
#ifndef SENSIRION_TEST_SETUP_H #define SENSIRION_TEST_SETUP_H #include <stdio.h> #include "CppUTest/TestHarness.h" // provide macros which will only be available in a future cpputest release // See https://github.com/cpputest/cpputest/pull/1423 #ifndef CHECK_EQUAL_ZERO #define CHECK_EQUAL_ZERO(actual) CHECK_EQUAL(0, (actual)) #endif #ifndef CHECK_EQUAL_ZERO_TEXT #define CHECK_EQUAL_ZERO_TEXT(actual, text) \ CHECK_EQUAL_TEXT(0, (actual), (text)) #endif // provide macro to check not zero #ifndef CHECK_NOT_EQUAL_ZERO_TEXT #define CHECK_NOT_EQUAL_ZERO_TEXT(actual, text) \ CHECK_TRUE_TEXT(0 != actual, (text)) #endif int main(int argc, char** argv); #endif /* SENSIRION_TEST_SETUP_H */
Sensirion/embedded-i2c-sen5x
sen5x_i2c.h
/* * THIS FILE IS AUTOMATICALLY GENERATED * * I2C-Generator: 0.3.0 * Yaml Version: 2.1.3 * Template Version: 0.7.0-109-gb259776 */ /* * Copyright (c) 2021, Sensirion AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name of Sensirion AG nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef SEN5X_I2C_H #define SEN5X_I2C_H #ifdef __cplusplus extern "C" { #endif #include "sensirion_config.h" /** * sen5x_start_measurement() - Starts a continuous measurement. * * After starting the measurement, it takes some time (~1s) until the first * measurement results are available. You could poll with the command * 0x0202 \"Read Data Ready\" to check when the results are ready to read. * * This command is only available in idle mode. If the device is already * in any measure mode, this command has no effect. * * @return 0 on success, an error code otherwise */ int16_t sen5x_start_measurement(void); /** * sen5x_start_measurement_without_pm() - Starts a continuous measurement * without PM. Only humidity, temperature, VOC and NOx are available in this * mode. Laser and fan are switched off to keep power consumption low. * * After starting the measurement, it takes some time (~1s) until the first * measurement results are available. You could poll with the command * 0x0202 \"Read Data Ready\" to check when the results are ready to read. * * This command is only available in idle mode. If the device is already * in any measure mode, this command has no effect. * * Supported sensors: SEN54, SEN55 * * @return 0 on success, an error code otherwise */ int16_t sen5x_start_measurement_without_pm(void); /** * sen5x_stop_measurement() - Stops the measurement and returns to idle mode. * * If the device is already in idle mode, this command has no effect. * * @return 0 on success, an error code otherwise */ int16_t sen5x_stop_measurement(void); /** * sen5x_read_data_ready() - This command can be used to check if new * measurement results are ready to read. The data ready flag is automatically * reset after reading the measurement values with the 0x03.. \"Read Measured * Values\" commands. * * @note During fan (auto-)cleaning, no measurement data is available for * several seconds and thus this flag will not be set until cleaning has * finished. So please expect gaps of several seconds at any time if fan * auto-cleaning is enabled. * * @param padding Padding byte, always 0x00. * * @param data_ready True (0x01) if data is ready, False (0x00) if not. When no * measurement is running, False will be returned. * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_data_ready(bool* data_ready); /** * sen5x_read_measured_values() - Returns the measured values. * * The command 0x0202 \"Read Data Ready\" can be used to check if new * data is available since the last read operation. If no new data is * available, the previous values will be returned again. If no data is * available at all (e.g. measurement not running for at least one * second), all values will be at their upper limit (0xFFFF for `uint16`, * 0x7FFF for `int16`). * * @param mass_concentration_pm1p0 Value is scaled with factor 10: * PM1.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm2p5 Value is scaled with factor 10: * PM2.5 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm4p0 Value is scaled with factor 10: * PM4.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm10p0 Value is scaled with factor 10: * PM10.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param ambient_humidity Value is scaled with factor 100: RH [%] = value / 100 * @note If this value is unknown, 0x7FFF is returned.* * * @param ambient_temperature Value is scaled with factor 200: * T [°C] = value / 200 * @note If this value is unknown, 0x7FFF is returned.* * * @param voc_index Value is scaled with factor 10: VOC Index = value / 10 * @note If this value is unknown, 0x7FFF is returned.* * * @param nox_index Value is scaled with factor 10: NOx Index = value / 10 * @note If this value is unknown, 0x7FFF is returned. During * the first 10..11 seconds after power-on or device reset, this * value will be 0x7FFF as well.* * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_measured_values(uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5, uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0, int16_t* ambient_humidity, int16_t* ambient_temperature, int16_t* voc_index, int16_t* nox_index); /** * sen5x_read_measured_raw_values() - Returns the measured raw values. The command 0x0202 \"Read Data Ready\" can be used to check if new data is available since the last read operation. If no new data is available, the previous values will be returned again. If no data is available at all (e.g. measurement not running for at least one second), all values will be at their upper limit (0xFFFF for `uint16`, 0x7FFF for `int16`). * * @param raw_humidity Value is scaled with factor 100: RH [%] = value / 100 * @note If this value is unknown, 0x7FFF is returned. * * @param raw_temperature Value is scaled with factor 200: T [°C] = value / 200 * @note If this value is unknown, 0x7FFF is returned. * * @param raw_voc Raw measured VOC ticks without scale factor. * @note If this value is unknown, 0xFFFF is returned. * * @param raw_nox Raw measured NOx ticks without scale factor. * @note If this value is unknown, 0xFFFF is returned. During * the first 10..11 seconds after power-on or device reset, this * value will be 0xFFFF as well.* * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_measured_raw_values(int16_t* raw_humidity, int16_t* raw_temperature, uint16_t* raw_voc, uint16_t* raw_nox); /** * sen5x_read_measured_values_sen50() - Returns the measured values for SEN50. * * The command 0x0202 \"Read Data Ready\" can be used to check if new * data is available since the last read operation. If no new data is * available, the previous values will be returned again. If no data is * available at all (e.g. measurement not running for at least one * second), all values will be at their upper limit (0xFFFF). * * @param mass_concentration_pm1p0 Value is scaled with factor 10: * PM1.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm2p5 Value is scaled with factor 10: * PM2.5 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm4p0 Value is scaled with factor 10: * PM4.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm10p0 Value is scaled with factor 10: * PM10.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_measured_values_sen50(uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5, uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0); /** * sen5x_read_measured_pm_values() - Returns the measured particulate matter * values. * * The command 0x0202 \"Read Data Ready\" can be used to check if new * data is available since the last read operation. If no new data is * available, the previous values will be returned again. If no data * is available at all (e.g. measurement not running for at least one * second), all values will be 0xFFFF. * * @param mass_concentration_pm1p0 Value is scaled with factor 10: * PM1.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm2p5 Value is scaled with factor 10: * PM2.5 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm4p0 Value is scaled with factor 10: * PM4.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param mass_concentration_pm10p0 Value is scaled with factor 10: * PM10.0 [µg/m³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param number_concentration_pm0p5 Value is scaled with factor 10: * PM0.5 [#/cm³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param number_concentration_pm1p0 Value is scaled with factor 10: * PM1.0 [#/cm³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param number_concentration_pm2p5 Value is scaled with factor 10: * PM2.5 [#/cm³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param number_concentration_pm4p0 Value is scaled with factor 10: * PM4.0 [#/cm³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param number_concentration_pm10p0 Value is scaled with factor 10: * PM10.0 [#/cm³] = value / 10 * @note If this value is unknown, 0xFFFF is returned. * * @param typical_particle_size Value is scaled with factor 1000: * Size [µm] = value / 1000 * @note If this value is unknown, 0xFFFF is returned. * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_measured_pm_values( uint16_t* mass_concentration_pm1p0, uint16_t* mass_concentration_pm2p5, uint16_t* mass_concentration_pm4p0, uint16_t* mass_concentration_pm10p0, uint16_t* number_concentration_pm0p5, uint16_t* number_concentration_pm1p0, uint16_t* number_concentration_pm2p5, uint16_t* number_concentration_pm4p0, uint16_t* number_concentration_pm10p0, uint16_t* typical_particle_size); /** * sen5x_start_fan_cleaning() - Starts the fan cleaning manually. The \"data * ready\"-flag will be cleared immediately and during the next few seconds, no * new measurement results will be available (old values will be returned). Once * the cleaning is finished, the \"data ready\"-flag will be set and new * measurement results will be available. * * When executing this command while cleaning is already active, the * command does nothing. * * If you stop the measurement while fan cleaning is active, the cleaning * will be aborted immediately. * * @note This command is only available in measure mode with PM measurement * enabled, i.e. only if the fan is already running. In any other state, this * command does nothing. * * @return 0 on success, an error code otherwise */ int16_t sen5x_start_fan_cleaning(void); /** * sen5x_set_temperature_offset_parameters() - Sets the temperature offset * parameters for the device. * * Supported sensors: SEN54, SEN55 * * @param temp_offset Constant temperature offset scaled with factor 200 (T [°C] * = value / 200). The default value is 0. * * @param slope Normalized temperature offset slope scaled with factor 10000 * (applied factor = value / 10000). The default value is 0. * * @param time_constant Time constant [s] how fast the new slope and offset will * be applied. After the specified value in seconds, 63% of the new slope and * offset are applied. A time constant of zero means the new values will be * applied immediately (within the next measure interval of 1 second). * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_temperature_offset_parameters(int16_t temp_offset, int16_t slope, uint16_t time_constant); /** * sen5x_get_temperature_offset_parameters() - Gets the temperature offset * parameters from the device. * * Supported sensors: SEN54, SEN55 * * @param temp_offset Constant temperature offset scaled with factor 200 (T [°C] * = value / 200). * * @param slope Normalized temperature offset slope scaled with factor 10000 * (applied factor = value / 10000). * * @param time_constant Time constant [s] how fast the slope and offset are * applied. After the specified value in seconds, 63% of the new slope and * offset are applied. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_temperature_offset_parameters(int16_t* temp_offset, int16_t* slope, uint16_t* time_constant); /** * sen5x_set_warm_start_parameter() - Sets the warm start parameter for the * device. * * Supported sensors: SEN54, SEN55 * * @note This parameter can be changed in any state of the device (and the * getter immediately returns the new value), but it is applied only the next * time starting a measurement, i.e. when sending a \"Start Measurement\" * command! So the parameter needs to be set *before* a warm-start measurement * is started. * * @param warm_start Warm start behavior as a value in the range from 0 (cold * start) to 65535 (warm start). The default value is 0. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_warm_start_parameter(uint16_t warm_start); /** * sen5x_get_warm_start_parameter() - Gets the warm start parameter from the * device. * * Supported sensors: SEN54, SEN55 * * @param warm_start Warm start behavior as a value in the range from 0 (cold * start) to 65535 (warm start). * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_warm_start_parameter(uint16_t* warm_start); /** * sen5x_set_voc_algorithm_tuning_parameters() - Sets the tuning parameters of * the VOC algorithm. * * Supported sensors: SEN54, SEN55 * * @note This command is available only in idle mode. In measure mode, this * command has no effect. In addition, it has no effect if at least one * parameter is outside the specified range. * * @param index_offset VOC index representing typical (average) conditions. * Allowed values are in range 1..250. The default value is 100. * * @param learning_time_offset_hours Time constant to estimate the VOC algorithm * offset from the history in hours. Past events will be forgotten after about * twice the learning time. Allowed values are in range 1..1000. The default * value is 12 hours. * * @param learning_time_gain_hours Time constant to estimate the VOC algorithm * gain from the history in hours. Past events will be forgotten after about * twice the learning time. Allowed values are in range 1..1000. The default * value is 12 hours. * * @param gating_max_duration_minutes Maximum duration of gating in minutes * (freeze of estimator during high VOC index signal). Set to zero to disable * the gating. Allowed values are in range 0..3000. The default value is 180 * minutes. * * @param std_initial Initial estimate for standard deviation. Lower value * boosts events during initial learning period, but may result in larger * device-to-device variations. Allowed values are in range 10..5000. The * default value is 50. * * @param gain_factor Gain factor to amplify or to attenuate the VOC index * output. Allowed values are in range 1..1000. The default value is 230. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_voc_algorithm_tuning_parameters( int16_t index_offset, int16_t learning_time_offset_hours, int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes, int16_t std_initial, int16_t gain_factor); /** * sen5x_get_voc_algorithm_tuning_parameters() - Gets the currently set tuning * parameters of the VOC algorithm. * * Supported sensors: SEN54, SEN55 * * @param index_offset VOC index representing typical (average) conditions. * * @param learning_time_offset_hours Time constant to estimate the VOC algorithm * offset from the history in hours. Past events will be forgotten after about * twice the learning time. * * @param learning_time_gain_hours Time constant to estimate the VOC algorithm * gain from the history in hours. Past events will be forgotten after about * twice the learning time. * * @param gating_max_duration_minutes Maximum duration of gating in minutes * (freeze of estimator during high VOC index signal). Zero disables the gating. * * @param std_initial Initial estimate for standard deviation. Lower value * boosts events during initial learning period, but may result in larger * device-to-device variations. * * @param gain_factor Gain factor to amplify or to attenuate the VOC index * output. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_voc_algorithm_tuning_parameters( int16_t* index_offset, int16_t* learning_time_offset_hours, int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes, int16_t* std_initial, int16_t* gain_factor); /** * sen5x_set_nox_algorithm_tuning_parameters() - Sets the tuning parameters of * the NOx algorithm. * * Supported sensors: SEN55 * * @note This command is available only in idle mode. In measure mode, this * command has no effect. In addition, it has no effect if at least one * parameter is outside the specified range. * * @param index_offset NOx index representing typical (average) conditions. * Allowed values are in range 1..250. The default value is 1. * * @param learning_time_offset_hours Time constant to estimate the NOx algorithm * offset from the history in hours. Past events will be forgotten after about * twice the learning time. Allowed values are in range 1..1000. The default * value is 12 hours. * * @param learning_time_gain_hours The time constant to estimate the NOx * algorithm gain from the history has no impact for NOx. This parameter is * still in place for consistency reasons with the VOC tuning parameters * command. This parameter must always be set to 12 hours. * * @param gating_max_duration_minutes Maximum duration of gating in minutes * (freeze of estimator during high NOx index signal). Set to zero to disable * the gating. Allowed values are in range 0..3000. The default value is 720 * minutes. * * @param std_initial The initial estimate for standard deviation parameter has * no impact for NOx. This parameter is still in place for consistency reasons * with the VOC tuning parameters command. This parameter must always be set * to 50. * * @param gain_factor Gain factor to amplify or to attenuate the NOx index * output. Allowed values are in range 1..1000. The default value is 230. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_nox_algorithm_tuning_parameters( int16_t index_offset, int16_t learning_time_offset_hours, int16_t learning_time_gain_hours, int16_t gating_max_duration_minutes, int16_t std_initial, int16_t gain_factor); /** * sen5x_get_nox_algorithm_tuning_parameters() - Gets the currently set tuning * parameters of the NOx algorithm. * * Supported sensors: SEN55 * * @param index_offset NOx index representing typical (average) conditions. * * @param learning_time_offset_hours Time constant to estimate the NOx algorithm * offset from the history in hours. Past events will be forgotten after about * twice the learning time. * * @param learning_time_gain_hours The time constant to estimate the NOx * algorithm gain from the history has no impact for NOx. This parameter is * still in place for consistency reasons with the VOC tuning parameters * command. * * @param gating_max_duration_minutes Maximum duration of gating in minutes * (freeze of estimator during high NOx index signal). Zero disables the gating. * * @param std_initial The initial estimate for standard deviation has no impact * for NOx. This parameter is still in place for consistency reasons with the * VOC tuning parameters command. * * @param gain_factor Gain factor to amplify or to attenuate the NOx index * output. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_nox_algorithm_tuning_parameters( int16_t* index_offset, int16_t* learning_time_offset_hours, int16_t* learning_time_gain_hours, int16_t* gating_max_duration_minutes, int16_t* std_initial, int16_t* gain_factor); /** * sen5x_set_rht_acceleration_mode() - Sets the RH/T acceleration mode. * * Supported sensors: SEN54, SEN55 * * @note This parameter can be changed in any state of the device (and the * getter immediately returns the new value), but it is applied only the next * time starting a measurement, i.e. when sending a \"Start Measurement\" * command. So the parameter needs to be set *before* a new measurement is * started. * * @param mode The new RH/T acceleration mode. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_rht_acceleration_mode(uint16_t mode); /** * sen5x_get_rht_acceleration_mode() - Gets the RH/T acceleration mode. * * Supported sensors: SEN54, SEN55 * * @param mode The current RH/T acceleration mode. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_rht_acceleration_mode(uint16_t* mode); /** * sen5x_set_voc_algorithm_state() - Sets the VOC algorithm state previously * received with the \"Get VOC Algorithm State\" command. * * Supported sensors: SEN54, SEN55 * * @note This command is only available in idle mode and the state will be * applied only once when starting the next measurement. Any further * measurements (i.e. when stopping and restarting the measure mode) will reset * the state to initial values. In measure mode, this command has no effect. * * @param state VOC algorithm state to restore. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_voc_algorithm_state(const uint8_t* state, uint8_t state_size); /** * sen5x_get_voc_algorithm_state() - Gets the current VOC algorithm state. This * data can be used to restore the state with the \"Set VOC Algorithm State\" * command after a short power cycle or device reset. * * This command can be used either in measure mode or in idle mode * (which will then return the state at the time when the measurement * was stopped). In measure mode, the state can be read each measure * interval to always have the latest state available, even in case of * a sudden power loss. * * Supported sensors: SEN54, SEN55 * * @param state Current VOC algorithm state. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_voc_algorithm_state(uint8_t* state, uint8_t state_size); /** * sen5x_set_fan_auto_cleaning_interval() - Sets the fan auto cleaning interval * for the device. * * @param interval Fan auto cleaning interval [s]. Set to zero to disable auto * cleaning. * * @return 0 on success, an error code otherwise */ int16_t sen5x_set_fan_auto_cleaning_interval(uint32_t interval); /** * sen5x_get_fan_auto_cleaning_interval() - Gets the fan auto cleaning interval * from the device. * * @param interval Fan auto cleaning interval [s]. Zero means auto cleaning is * disabled. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_fan_auto_cleaning_interval(uint32_t* interval); /** * sen5x_get_product_name() - Gets the product name from the device. * * @param product_name Null-terminated ASCII string containing the product name. * Up to 32 characters can be read from the device. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_product_name(unsigned char* product_name, uint8_t product_name_size); /** * sen5x_get_serial_number() - Gets the serial number from the device. * * @param serial_number Null-terminated ASCII string containing the serial * number. Up to 32 characters can be read from the device. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_serial_number(unsigned char* serial_number, uint8_t serial_number_size); /** * sen5x_get_version() - Gets the version information for the hardware, firmware * and communication protocol. * * @param firmware_major Firmware major version number. * * @param firmware_minor Firmware minor version number. * * @param firmware_debug Firmware debug state. If the debug state is set, the * firmware is in development. * * @param hardware_major Hardware major version number. * * @param hardware_minor Hardware minor version number. * * @param protocol_major Protocol major version number. * * @param protocol_minor Protocol minor version number. * * @param padding Padding byte, ignore this. * * @return 0 on success, an error code otherwise */ int16_t sen5x_get_version(uint8_t* firmware_major, uint8_t* firmware_minor, bool* firmware_debug, uint8_t* hardware_major, uint8_t* hardware_minor, uint8_t* protocol_major, uint8_t* protocol_minor); /** * sen5x_read_device_status() - Reads the current device status. * Use this command to get detailed information about the device status. * The device status is encoded in flags. Each device status flag * represents a single bit in a 32-bit integer value. If more than one * error is present, the device status register value is the sum of the * corresponding flag values. For details about the available flags, * refer to the device status flags documentation. * * @note The status flags of type \"Error\" are sticky, i.e. they are not * cleared automatically even if the error condition no longer exists. So they * can only be cleared manually with the command 0xD210 \"Read And Clear Device * Status\" or with a device reset. All other flags are not sticky, i.e. they * are cleared automatically if the trigger condition disappears. * * @param device_status Device status (32 flags as an integer value). For * details, please refer to the device status flags documentation. * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_device_status(uint32_t* device_status); /** * sen5x_read_and_clear_device_status() - Reads the current device status (like * command 0xD206 \"Read Device Status\") and afterwards clears all flags. * * @param device_status Device status (32 flags as an integer value) **before** * clearing it. For details, please refer to the device status flags * documentation. * * @return 0 on success, an error code otherwise */ int16_t sen5x_read_and_clear_device_status(uint32_t* device_status); /** * sen5x_device_reset() - Executes a reset on the device. This has the same * effect as a power cycle. * * @return 0 on success, an error code otherwise */ int16_t sen5x_device_reset(void); #ifdef __cplusplus } #endif #endif /* SEN5X_I2C_H */
moreira/react-native-piwik-manager
ios/BNFPiwik/Piwik.h
<gh_stars>0 // // Piwik // #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #if __has_include(<React/RCTBridgeModule.h>) #import <React/RCTBridgeModule.h> #elif __has_include("RCTBridgeModule.h") #import "RCTBridgeModule.h" #elif __has_include("React/RCTBridgeModule.h") #import "React/RCTBridgeModule.h" // Required when used as a Pod in a Swift project #endif @interface Piwik : NSObject <RCTBridgeModule> -(void) initTracker: (NSString*)url id:(NSNumber* _Nonnull) id; -(void) trackScreen: (NSString* _Nonnull)screen title:(NSString*) title; -(void) setUserId:(NSString* _Nonnull)userID; -(void) setAppOptOut:(BOOL)isOptedOut; -(void) trackGoal: (NSUInteger)goal values:(NSDictionary* _Nonnull) values; -(void) trackEvent: (NSString* _Nonnull)category action:(NSString* _Nonnull) action values:(NSDictionary* _Nonnull) values; -(void) trackAppDownload; @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/Model/BBSModel.h
// // BBSModel.h // MyCar // // Created by 🐵 on 16-5-26. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface BBSModel : NSObject @property (nonatomic,copy) NSString * postTitle; @property (nonatomic,copy) NSString * postLink; @property (nonatomic,copy) NSString * author; @property (nonatomic,copy) NSString * forumName; @property (nonatomic,assign) int viewCount; @property (nonatomic,copy) NSString * postImage; @property (nonatomic,assign) int replyCount; @property (nonatomic,copy) NSString * createDate; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Controller/NewsViewController.h
<gh_stars>0 // // NewsViewController.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import "BaseHeadNewsViewController.h" @interface NewsViewController : BaseHeadNewsViewController @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Controller/CarViewController.h
<filename>MyCar/MyCar/HeadNews/Controller/CarViewController.h<gh_stars>0 // // CarViewController.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import "BaseHeadNewsViewController.h" @interface CarViewController : BaseHeadNewsViewController @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Model/DrawerModel.h
// // DrawerModel.h // MyCar // // Created by 🐵 on 16-5-28. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface DrawerModel : NSObject @property (nonatomic,copy) NSString * serialId; @property (nonatomic,copy) NSString * serialName; @property (nonatomic,copy) NSString * Picture; @property (nonatomic,copy) NSString * dealerPrice; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Model/HeadButtonModel.h
// // HeadButtonModel.h // MyCar // // Created by 🐵 on 16-5-22. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface HeadButtonModel : NSObject @property (nonatomic,copy) NSString * ID; @property (nonatomic,copy) NSString * title; @property (nonatomic,copy) NSString * converImg; @property (nonatomic,copy) NSString * link; @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/View/HotTableViewCell.h
<filename>MyCar/MyCar/Community/View/HotTableViewCell.h // // HotTableViewCell.h // MyCar // // Created by 🐵 on 16-5-26. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "BBSModel.h" @interface HotTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UILabel *titleLabel; @property (strong, nonatomic) IBOutlet UILabel *authorLabel; @property (strong, nonatomic) IBOutlet UILabel *forumNameLabel; @property (strong, nonatomic) IBOutlet UILabel *viewCountLabel; - (void)loadDataFromModel:(BBSModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/ThreeLibrary/HttpRequest.h
<gh_stars>0 // // HttpRequest.h // Travel // // Created by 🐵 on 16-5-19. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface HttpRequest : NSObject + (void)startHttpRequestWithURL:(NSString *)url andParmenter:(NSDictionary *)parmeters andReturnBlock:(void(^)(NSData * data,NSError * error))block; @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/Controller/CommunityDetailViewController.h
// // CommunityDetailViewController.h // MyCar // // Created by 🐵 on 16-5-27. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface CommunityDetailViewController : UIViewController @property (nonatomic,copy) NSString * url; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/View/ButtonOnHeadView.h
// // ButtonOnHeadView.h // MyCar // // Created by 🐵 on 16-5-22. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "HeadButtonModel.h" @interface ButtonOnHeadView : UIButton @property (nonatomic,strong) UIImageView * ImageView; @property (nonatomic,strong) UILabel * label; - (void)loadDataFromModel:(HeadButtonModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Controller/DetailViewController.h
// // DetailViewController.h // MyCar // // Created by 🐵 on 16-5-29. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface DetailViewController : UIViewController @property (nonatomic,copy) NSString * serialId; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Controller/RightTableViewController.h
<filename>MyCar/MyCar/ChooseCar/Controller/RightTableViewController.h // // RightTableViewController.h // MyCar // // Created by 🐵 on 16-5-28. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface RightTableViewController : UITableViewController @property (nonatomic,copy) NSString * masterId; @property (nonatomic,copy) NSString * logoUrl; @property (nonatomic,copy) NSString * masterName; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Model/BrandModel.h
// // BrandModel.h // MyCar // // Created by 🐵 on 16-5-30. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface BrandModel : NSObject @property (nonatomic,copy) NSString * introduction; @property (nonatomic,copy) NSString * logoMeaning; @property (nonatomic,copy) NSString * masterId; @property (nonatomic,copy) NSString * masterName; @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/Controller/BaseBBsViewController.h
<reponame>shuaigeqing/ZQCar // // BaseBBsViewController.h // MyCar // // Created by 🐵 on 16-5-26. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> typedef enum { BBSVIEW = 1, HOT, }VIEW_TYPE; @interface BaseBBsViewController : UIViewController @property (nonatomic,strong) UITableView * tableView; @property (nonatomic,strong) NSMutableArray * dataArr; @property (nonatomic,copy) NSString * url; @property (nonatomic,assign) int page; @property (nonatomic,assign)VIEW_TYPE type; - (void)setMyUrl; - (void)loadData; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/View/AVTableViewCell.h
// // AVTableViewCell.h // MyCar // // Created by 🐵 on 16-5-23. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "NewsCellModel.h" #import <AVFoundation/AVFoundation.h> #import <MediaPlayer/MediaPlayer.h> @interface AVTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UIView *View; @property (strong, nonatomic) IBOutlet UILabel *titleLabel; @property (strong, nonatomic) IBOutlet UILabel *srcLabel; @property (strong, nonatomic) IBOutlet UILabel *countLabel; @property (strong, nonatomic) IBOutlet UILabel *visitLabel; @property (strong, nonatomic) IBOutlet UIImageView *IV; @property (strong, nonatomic) IBOutlet UILabel *durationLabel; @property (nonatomic,strong) MPMoviePlayerController * player; - (void)loadAvFromModel:(NewsCellModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Controller/BrandViewController.h
// // BrandViewController.h // MyCar // // Created by 🐵 on 16-5-30. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface BrandViewController : UIViewController @property (nonatomic,copy) NSString * masterId; @property (nonatomic,copy) NSString * masterName; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/View/ClassTableViewCell.h
// // ClassTableViewCell.h // MyCar // // Created by 🐵 on 16-5-30. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "ChooseModel.h" @interface ClassTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UIImageView *IV; @property (strong, nonatomic) IBOutlet UILabel *Label; - (void)loadDataFromModel:(ChooseModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Controller/BaseHeadNewsViewController.h
// // BaseHeadNewsViewController.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "TopScrollView.h" #import <AVFoundation/AVFoundation.h> #import <MediaPlayer/MediaPlayer.h> @interface BaseHeadNewsViewController : UIViewController @property (nonatomic,strong) UITableView * tableView; @property (nonatomic,strong) NSMutableArray * dataArr; @property (nonatomic,strong) NSMutableArray * buttonArr; @property (nonatomic,copy) NSString * url; @property (nonatomic,copy) NSString * buttonURL; @property (nonatomic,strong) TopScrollView * topScroll; @property (nonatomic,assign) int page; @property (nonatomic,assign) int choose; @property (nonatomic,strong) MPMoviePlayerController * player; - (void)setMyUrl; - (void)loadData; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Controller/NewsDetailViewController.h
<reponame>shuaigeqing/ZQCar // // NewsDetailViewController.h // MyCar // // Created by 🐵 on 16-5-25. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface NewsDetailViewController : UIViewController @property (nonatomic,copy) NSString * NewsID; @property (nonatomic,assign) NSInteger choose; @property (nonatomic,copy) NSString * path; @property (nonatomic,copy) NSString * name; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Model/ChooseModel.h
// // ChooseModel.h // MyCar // // Created by 🐵 on 16-5-27. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface ChooseModel : NSObject @property (nonatomic,copy) NSString * masterId; @property (nonatomic,copy) NSString * name; @property (nonatomic,copy) NSString * logoUrl; @property (nonatomic,copy) NSString * initial; @property (nonatomic,copy) NSString * uv; @end
shuaigeqing/ZQCar
MyCar/MyCar/Base/BaseTabBarController.h
// // BaseTabBarController.h // Travel // // Created by 🐵 on 16-5-19. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface BaseTabBarController : UITabBarController @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/View/BBSTableViewCell.h
// // BBSTableViewCell.h // MyCar // // Created by 🐵 on 16-5-26. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "BBSModel.h" @interface BBSTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UIImageView *IV; @property (strong, nonatomic) IBOutlet UILabel *titleLabel; @property (strong, nonatomic) IBOutlet UILabel *authorLabel; @property (strong, nonatomic) IBOutlet UILabel *replyCountLabel; - (void)loadDataFromModel:(BBSModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/Model/ContainDrawerModel.h
<reponame>shuaigeqing/ZQCar // // ContainDrawerModel.h // MyCar // // Created by 🐵 on 16-5-28. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface ContainDrawerModel : NSObject @property (nonatomic,copy) NSString * brandId; @property (nonatomic,copy) NSString * brandName; @property (nonatomic,strong) NSMutableArray * serialListArr; @end
shuaigeqing/ZQCar
MyCar/MyCar/ThreeLibrary/MMProgressHUD/Source/MMProgressHUDWindow.h
// // MMProgressHUDWindow.h // MMProgressHUDDemo // // Created by <NAME> on 6/28/12. // Copyright (c) 2012 Mutual Mobile. All rights reserved. // #import <UIKit/UIKit.h> #import "MMProgressHUD.h" @interface MMProgressHUDWindow : UIWindow /** The window that was key at presentation time. Used to grab the view controller associated with the key window for rotation callbacks if they are available. */ @property (nonatomic, strong) UIWindow *oldWindow; @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/Controller/CommunityVC.h
<reponame>shuaigeqing/ZQCar // // CommunityVC.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface CommunityVC : UIViewController @end
shuaigeqing/ZQCar
MyCar/MyCar/Community/Controller/HotViewController.h
// // HotViewController.h // MyCar // // Created by 🐵 on 16-5-26. // Copyright (c) 2016年 MC. All rights reserved. // #import "BaseBBsViewController.h" @interface HotViewController : BaseBBsViewController @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/Model/NewsCellModel.h
<reponame>shuaigeqing/ZQCar // // NewsCellModel.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import <Foundation/Foundation.h> @interface NewsCellModel : NSObject @property (nonatomic,assign) int commentCount; @property (nonatomic,copy) NSString * newsId; @property (nonatomic,copy) NSString * picCover; @property (nonatomic,copy) NSString * src; @property (nonatomic,copy) NSString * title; @property (nonatomic,assign) int type; @property (nonatomic,copy) NSString * mp4Link; @property (nonatomic,copy) NSString * duration; @property (nonatomic,copy) NSString * mediaName; @property (nonatomic,assign) int totalvisit; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/View/NewsTableViewCell.h
<reponame>shuaigeqing/ZQCar<gh_stars>0 // // NewsTableViewCell.h // MyCar // // Created by 🐵 on 16-5-20. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "NewsCellModel.h" @interface NewsTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UIImageView *coverImageView; @property (strong, nonatomic) IBOutlet UILabel *titleLabel; @property (strong, nonatomic) IBOutlet UILabel *srcLabel; @property (strong, nonatomic) IBOutlet UILabel *countLabel; - (void)loadDataFromModel:(NewsCellModel *)model; @end
shuaigeqing/ZQCar
MyCar/MyCar/HeadNews/View/TopScrollView.h
<gh_stars>0 // // TopScrollView.h // MyCar // // Created by 🐵 on 16-5-21. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> @interface TopScrollView : UIView @property (nonatomic,strong) UIScrollView * scrollView; @property (nonatomic,strong) UIPageControl * pageController; @property (nonatomic,assign) int page; @property (nonatomic,strong) NSArray * dataArr; @property (nonatomic,assign) int choose; - (void) loadDataFromArray:(NSArray *)array; @end
shuaigeqing/ZQCar
MyCar/MyCar/ChooseCar/View/BrandTableViewCell.h
// // BrandTableViewCell.h // MyCar // // Created by 🐵 on 16-5-30. // Copyright (c) 2016年 MC. All rights reserved. // #import <UIKit/UIKit.h> #import "BrandModel.h" @interface BrandTableViewCell : UITableViewCell @property (strong, nonatomic) IBOutlet UILabel *Label; @end
danielnagy81/AnimatingHeaderView
MovingImageTest/MovingImageView.h
// // MovingImageView.h // MovingImageTest // // Created by Daniel_Nagy on 19/04/16. // Copyright © 2016 NDani. All rights reserved. // @import UIKit; typedef NS_ENUM(NSInteger, MovingImageViewImageAnimationType) { TopToBottom = 0, ZoomIn }; @interface MovingImageView : UIView @property (nonatomic) NSTimeInterval fadeTime; @property (nonatomic) MovingImageViewImageAnimationType animationType; @property (nonatomic) BOOL restartAfterFinish; @property (nonatomic) NSTimeInterval animationTime; @property (nonatomic) NSArray <UIImage *> * _Nonnull images; - (instancetype _Nullable)initWithImage:(UIImage * _Nonnull)image; - (instancetype _Nullable)initWithImage:(UIImage * _Nonnull)image withFadeView:(UIView * _Nullable)fadeView; - (instancetype _Nullable)initWithImages:(NSArray <UIImage *> * _Nonnull)images; - (instancetype _Nullable)initWithImages:(NSArray <UIImage *> * _Nonnull)images withFadeView:(UIView * _Nullable)fadeView; - (void)startImageAnimation; @end
mylxiaoyi/maptk
gui/tools/AbstractTool.h
/*ckwg +29 * Copyright 2017 by Kitware, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * * Neither the name Kitware, Inc. nor the names of any contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef MAPTK_ABSTRACTTOOL_H_ #define MAPTK_ABSTRACTTOOL_H_ #include <vital/config/config_block_types.h> #include <vital/logger/logger.h> #include <vital/types/camera_map.h> #include <vital/types/landmark_map.h> #include <vital/types/feature_track_set.h> #include <vital/types/image_container.h> #include <vtkSmartPointer.h> #include <vtkImageData.h> #include <qtGlobal.h> #include <QtGui/QAction> class AbstractToolPrivate; /// A class to hold data that is modified by the tool class ToolData { public: typedef kwiver::vital::feature_track_set_sptr feature_track_set_sptr; typedef kwiver::vital::camera_map_sptr camera_map_sptr; typedef kwiver::vital::landmark_map_sptr landmark_map_sptr; typedef kwiver::vital::config_block_sptr config_block_sptr; typedef vtkSmartPointer<vtkImageData> depth_sptr; /// Deep copy the feature tracks into this data class void copyTracks(feature_track_set_sptr const&); /// Deep copy the cameras into this data class void copyCameras(camera_map_sptr const&); /// Deep copy the landmarks into this data class void copyLandmarks(landmark_map_sptr const&); /// Deep copy a depth image into this data class void copyDepth(depth_sptr const&); unsigned int activeFrame; std::string videoPath; feature_track_set_sptr tracks; depth_sptr active_depth; camera_map_sptr cameras; landmark_map_sptr landmarks; config_block_sptr config; kwiver::vital::logger_handle_t logger; }; Q_DECLARE_METATYPE(std::shared_ptr<ToolData>) class AbstractTool : public QAction { Q_OBJECT public: typedef kwiver::vital::feature_track_set_sptr feature_track_set_sptr; typedef kwiver::vital::camera_map_sptr camera_map_sptr; typedef kwiver::vital::landmark_map_sptr landmark_map_sptr; typedef kwiver::vital::config_block_sptr config_block_sptr; typedef vtkSmartPointer<vtkImageData> depth_sptr; enum Output { Tracks = 0x1, Cameras = 0x2, Landmarks = 0x4, ActiveFrame = 0x8, KeyFrames = 0x10, Depth = 0x20 }; Q_DECLARE_FLAGS(Outputs, Output) explicit AbstractTool(QObject* parent = 0); virtual ~AbstractTool(); /// Get the types of output produced by the tool. virtual Outputs outputs() const = 0; /// Get if the tool can be canceled. /// /// This method must be overridden by tool implementations. It should return /// \c false if the tool cannot be interrupted by the user. A return value of /// \c true implies that calling cancel() may have an effect. virtual bool isCancelable() const = 0; /// Return a shared pointer to the tools data std::shared_ptr<ToolData> data(); /// Set the active frame to be used by the tool. void setActiveFrame(unsigned int frame); /// Set the image paths to be used as input to the tool. void setImagePaths(std::vector<std::string> const&); /// Set the feature tracks to be used as input to the tool. void setTracks(feature_track_set_sptr const&); /// Set the cameras to be used as input to the tool. void setCameras(camera_map_sptr const&); /// Set the landmarks to be used as input to the tool. void setLandmarks(landmark_map_sptr const&); /// Set the video source path. void setVideoPath(std::string const&); /// Set the config file if any void setConfig(config_block_sptr&); /// Execute the tool. /// /// Tool implementations should override this method to verify that they have /// sufficient data before calling the base implementation. /// /// \param window Optional pointer to a widget to use as a context for any /// dialogs that the tool may need to display. /// /// \return \c true if tool execution was started successfully, otherwise /// \c false. virtual bool execute(QWidget* window = 0); /// Get the active frame. unsigned int activeFrame() const; /// Get tracks. /// /// This returns the new tracks resulting from the tool execution. If the /// tool does not output tracks, the tracks will be a copy of the input /// tracks. /// /// This may also be used by tool implementations to get the input tracks. /// (The tracks will be a copy that can be safely modified.) /// /// \warning Users must not call this method while the tool is executing, /// as doing so may not be thread safe. feature_track_set_sptr tracks() const; /// Get cameras. /// /// This returns the new cameras resulting from the tool execution. If the /// tool does not output cameras, the cameras will be a copy of the input /// cameras. /// /// This may also be used by tool implementations to get the input cameras. /// (The cameras will be a copy that can be safely modified.) /// /// \warning Users must not call this method while the tool is executing, /// as doing so may not be thread safe. camera_map_sptr cameras() const; /// Get landmarks. /// /// This returns the new landmarks resulting from the tool execution. If the /// tool does not output landmarks, the landmarks will be a copy of the input /// landmarks. /// /// This may also be used by tool implementations to get the input landmarks. /// (The landmarks will be a copy that can be safely modified.) /// /// \warning Users must not call this method while the tool is executing, /// as doing so may not be thread safe. landmark_map_sptr landmarks() const; signals: /// Emitted when the tool execution is completed. void completed(); /// Emitted when an intermediate update of the data is available to show progress. void updated(std::shared_ptr<ToolData>); /// Emitted when the tool execution terminates due to user cancellation. void canceled(); public slots: /// Ask the tool to cancel execution. /// /// This sets a flag indicating that the user has requested the tool /// execution should halt. The tool may or may not honor such a request. /// /// \sa canceled, isCancelable virtual void cancel(); protected: /// Execute the tool. /// /// This method must be overridden by tool implementations. The default /// implementation of execute() calls this method in a separate thread. virtual void run() = 0; /// Check if the user has requested that tool execution be canceled. bool isCanceled() const; /// Test if the tool has track data. /// /// \return \c true if the tool data has a non-zero number of feature tracks, /// otherwise \c false bool hasTracks() const; /// Test if the tool has camera data. /// /// \return \c true if the tool data has a non-zero number of cameras, /// otherwise \c false bool hasCameras() const; /// Test if the tool has landmark data. /// /// \return \c true if the tool data has a non-zero number of landmarks, /// otherwise \c false bool hasLandmarks() const; /// Test if the tool has video data. /// /// \return \c true if the tool data has an associated video source, /// otherwise \c false bool hasVideoSource() const; /// Set the tracks produced by the tool. /// /// This sets the tracks that are produced by the tool as output. Unlike /// setTracks, this does not make a deep copy of the provided tracks. void updateTracks(feature_track_set_sptr const&); /// Set the cameras produced by the tool. /// /// This sets the cameras that are produced by the tool as output. Unlike /// setCameras, this does not make a deep copy of the provided cameras. void updateCameras(camera_map_sptr const&); /// Set the depth map produced by the tool. void updateDepth(depth_sptr const& newDepth); /// Set the landmarks produced by the tool. /// /// This sets the landmarks that are produced by the tool as output. Unlike /// setCameras, this does not make a deep copy of the provided landmarks. void updateLandmarks(landmark_map_sptr const&); private: QTE_DECLARE_PRIVATE_RPTR(AbstractTool) QTE_DECLARE_PRIVATE(AbstractTool) QTE_DISABLE_COPY(AbstractTool) }; Q_DECLARE_OPERATORS_FOR_FLAGS(AbstractTool::Outputs) #endif
horsicq/XProcessModulesWidget
xprocessmoduleswidget.h
/* Copyright (c) 2022 hors<<EMAIL>> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef XPROCESSMODULESWIDGET_H #define XPROCESSMODULESWIDGET_H #include <QMenu> #include <QWidget> #include <QStandardItemModel> #include <QDesktopServices> #include <QFuture> #include <QtConcurrent> #include "dialogdumpprocess.h" #include "xprocess.h" #include "xshortcutswidget.h" #include "xinfodb.h" namespace Ui { class XProcessModulesWidget; } class XProcessModulesWidget : public XShortcutsWidget { Q_OBJECT enum HEADER_COLUMN { HEADER_COLUMN_ADDRESS=0, HEADER_COLUMN_SIZE, HEADER_COLUMN_NAME, HEADER_COLUMN_FILENAME, __HEADER_COLUMN_size }; enum SC { SC_DUMPTOFILE=0, SC_SHOWIN_FOLDER, __SC_SIZE }; enum USERROLE { USERROLE_SIZE=0, USERROLE_ADDRESS, USERROLE_FILENAME }; public: explicit XProcessModulesWidget(QWidget *pParent=nullptr); ~XProcessModulesWidget(); void setData(qint64 nProcessId,bool bReload=true); void setXInfoDB(XInfoDB *pXInfoDB,bool bReload=true); void reload(); private: void deleteOldModel(); protected: virtual void registerShortcuts(bool bState); private slots: void on_pushButtonSave_clicked(); void on_pushButtonReload_clicked(); void on_tableViewModules_customContextMenuRequested(const QPoint &pos); protected slots: void _dumpToFileSlot(); void _showInFolderSlot(); private: Ui::XProcessModulesWidget *ui; qint64 g_nProcessId; XInfoDB *g_pXInfoDB; QStandardItemModel *g_pModel; QStandardItemModel *g_pOldModel; QShortcut *shortCuts[__SC_SIZE]; }; #endif // XPROCESSMODULESWIDGET_H
COM14/PD-Arcade-Lights
source-code/PD Arcade Lights.h
<filename>source-code/PD Arcade Lights.h #include "pch.h" #include <Windows.h> #include "PluginConfigApi.h" #include "framework.h" #define sync 0xff #define offset 0xc9 using namespace System; using namespace System::IO::Ports; uint32_t Rate; uint8_t Selected_Port, Delay; void loadConfig() { Selected_Port = GetPrivateProfileIntW(L"general", L"COM Port", 8, CONFIG_FILE); Rate = GetPrivateProfileIntW(L"general", L"Rate", 38400, CONFIG_FILE); Delay = GetPrivateProfileIntW(L"general", L"Delay", 1, CONFIG_FILE); return; } void onAttach() { int sides, buttons, ob, os; SerialPort port("COM8", Rate); HWND hwnd = FindWindowA(NULL, "Hatsune Miku Project DIVA Arcade Future Tone"); for (; hwnd == NULL; hwnd = FindWindowA(NULL, "Hatsune Miku Project DIVA Arcade Future Tone") ) {Sleep(6000);} try{port.Open();} catch (...){printf("[PD Arcade Lights] failed to open port\n"); return;} printf("[PD Arcade Lights] connected\n"); while (port.IsOpen == true) { memcpy((void*)&buttons, (LPVOID)0x00014119B950, sizeof(buttons)); memcpy((void*)&sides, (LPVOID)0x000140EDA330, sizeof(sides)); sides = sides + offset; memcpy((void*)&sides, (LPVOID)sides, sizeof(sides)); array<System::Byte>^ out = { sync,buttons,sides }; if(os!=sides || ob!=buttons) port.Write(out, 0, 3); os = sides; ob = buttons; Sleep(Delay); } port.Close(); } BOOL APIENTRY DllMain(HMODULE hModule,DWORD ul_reason_for_call,LPVOID lpReserved) { switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hModule); loadConfig(); CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)onAttach, NULL, 0, NULL); break; case DLL_PROCESS_DETACH: break; } return TRUE; } PluginConfig::PluginConfigOption config[] = { { PluginConfig::CONFIG_GROUP_START, new PluginConfig::PluginConfigGroupData{ L"Settings", 110 } }, { PluginConfig::CONFIG_NUMERIC, new PluginConfig::PluginConfigNumericData{ L"Selected_Port", L"general", CONFIG_FILE, L"COM Port(not working)", L"set to 8", 8, 1, 256} }, { PluginConfig::CONFIG_DROPDOWN_NUMBER, new PluginConfig::PluginConfigDropdownNumberData{ L"Rate", L"general", CONFIG_FILE, L"Data rate", L"COM Port data rate", 38400, std::vector<int>({ 9600, 38400, 115200 }), false } }, { PluginConfig::CONFIG_NUMERIC, new PluginConfig::PluginConfigNumericData{ L"Delay", L"general", CONFIG_FILE, L"Delay(ms)", L"Delay between scans (0-100ms)\n0 is not recommended", 1, 0, 100} }, }; extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) { return L"PD Arcade Lights"; } extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) { return L"rets.str()"; } extern "C" __declspec(dllexport) PluginConfig::PluginConfigArray GetPluginOptions(void) { return PluginConfig::PluginConfigArray{ _countof(config), config }; }
COM14/PD-Arcade-Lights
source-code/PluginConfigApi.h
<reponame>COM14/PD-Arcade-Lights<gh_stars>1-10 #pragma once #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #include <windows.h> #include <vector> // resolution class to store and sort the width and height easily class resolution { public: unsigned int width; unsigned int height; resolution() { width = 0; height = 0; } resolution(unsigned int width, unsigned int height) { resolution::width = width; resolution::height = height; } bool operator ==(const resolution &res2) { return width == res2.width && height == res2.height; } // in comparisons width takes priority because it's usually displayed first bool operator <(const resolution &res2) { if (width == res2.width) return height < res2.height; else return width < res2.width; } bool operator >(const resolution &res2) { if (width == res2.width) return height > res2.height; else return width > res2.width; } }; namespace PluginConfig { #pragma pack(push, 1) enum ConfigType { CONFIG_BOOLEAN, CONFIG_NUMERIC, CONFIG_STRING, CONFIG_DROPDOWN_INDEX, CONFIG_DROPDOWN_TEXT, CONFIG_DROPDOWN_NUMBER, CONFIG_RESOLUTION, CONFIG_GROUP_START, CONFIG_GROUP_END, CONFIG_BUTTON, CONFIG_SPACER }; struct PluginConfigBooleanData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; bool defaultVal; bool saveAsString; }; struct PluginConfigNumericData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; int defaultVal; int minVal; int maxVal; }; struct PluginConfigStringData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; LPCWSTR defaultVal; bool useUtf8; }; struct PluginConfigDropdownIndexData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; int defaultVal; std::vector<LPCWSTR> valueStrings; }; struct PluginConfigDropdownTextData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; LPCWSTR defaultVal; std::vector<LPCWSTR> valueStrings; bool editable; bool useUtf8; }; struct PluginConfigDropdownNumberData { LPCWSTR iniVarName; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; int defaultVal; std::vector<int> valueInts; bool editable; }; struct PluginConfigResolutionData { LPCWSTR iniVarName; LPCWSTR iniVarName2; LPCWSTR iniSectionName; LPCWSTR iniFilePath; LPCWSTR friendlyName; LPCWSTR description; resolution defaultVal; std::vector<resolution> valueResolutions; bool editable; }; struct PluginConfigGroupData { LPCWSTR name; int height; }; struct PluginConfigButtonData { LPCWSTR friendlyName; LPCWSTR description; void(*func)(); }; struct PluginConfigSpacerData { int height; }; struct PluginConfigOption { ConfigType cfgType; void* data; }; struct PluginConfigArray { int len; PluginConfigOption* options; }; #pragma pack(pop) extern "C" __declspec(dllexport) LPCWSTR GetBuildDate(void) { WCHAR utf16buf[128]; MultiByteToWideChar(CP_UTF8, 0, __DATE__, -1, utf16buf, 128); return _wcsdup(utf16buf); } }
COM14/PD-Arcade-Lights
source-code/framework.h
#include <windows.h> #include <string> std::wstring ExePath() { WCHAR buffer[MAX_PATH]; GetModuleFileNameW(NULL, buffer, MAX_PATH); return std::wstring(buffer); } std::wstring DirPath() { std::wstring exepath = ExePath(); std::wstring::size_type pos = exepath.find_last_of(L"\\/"); return exepath.substr(0, pos); } std::wstring CONFIG_FILE_STRING = DirPath() + L"\\plugins\\Lights.ini"; LPCWSTR CONFIG_FILE = CONFIG_FILE_STRING.c_str();
AlgoTyc/Computergrafik
model.h
#ifndef MODEL_H #define MODEL_H #include <QOpenGLBuffer> #include <QOpenGLVertexArrayObject> #include <QString> #include <QOpenGLFunctions> #include <QOpenGLFunctions_3_3_Core> #include "dcommon.h" class Model : QOpenGLFunctions_3_3_Core { public: Model(); void initGL(const QString &filename); void drawElements(); void finiGL(); private: QOpenGLBuffer m_vbo; QOpenGLBuffer m_ibo; QOpenGLVertexArrayObject m_vao; unsigned m_iboCount = 0; }; #endif // MODEL_H
AlgoTyc/Computergrafik
modelloader.h
/* * ModelLoader class * A simple interface to the Assimp library to generate arrays for Qt * to be used as Buffer Objects within OpenGL * * v0.6 beta, 2018 * * <EMAIL> * * Released under THE BEER-WARE LICENSE (Rev. 42) * */ #ifndef MODELLOADER_H #define MODELLOADER_H #include <assimp/Importer.hpp> #include <assimp/scene.h> #include <assimp/postprocess.h> #include <qopengl.h> #include <QString> #include <QDataStream> #include <QDebug> #include <QFile> #include <QFileInfo> #include <cassert> #define ML_VERTPOS_COUNT 3 #define ML_NORMAL_COUNT 3 #define ML_TEXCOOR_COUNT 2 class ModelLoader { public: ModelLoader() : _hasScene(false) , scene(NULL) {} /* Note: * Assimp::Importer cleans up after itself, * freeing the scene it previously returned */ ~ModelLoader() {} /* TODO: this method has some weak error handling */ bool loadObjectFromFile(const QString& name) { if (_hasScene) { qWarning() << "Already loaded a model"; return false; } // Open file; this also works for Qt resource containers QFile file(name); bool success = file.open(QIODevice::ReadOnly); if (!success) { qWarning() << "Could not open file " << name; return false; } // Read file contents into buffer QByteArray buffer = file.readAll(); file.close(); // Retrieve file extension to give the importer a hint which module to use QFileInfo fileInfo(name); QByteArray ext = fileInfo.completeSuffix().toLatin1(); // load scene with triangulation, removing identical vertices // and generating normals, if necessary scene = importer.ReadFileFromMemory(buffer.constData(), buffer.length(), aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_GenSmoothNormals, ext.constData()); // check if import was successful if(!scene) { /* TODO: do something with importer.GetErrorString() */ qInfo()<<importer.GetErrorString(); qWarning() << "Import failed"; return false; } // check if there is at least one mesh if (scene->mNumMeshes == 0 || scene->mMeshes[0]->mNumFaces == 0) { importer.FreeScene(); qWarning() << "No mesh found"; return false; } // everything checked out _hasScene = true; return true; } // Generates a VBO with v1.x, v1.y, v1.z, v1.w, v2.x, ... void genSimpleVBO(GLfloat* vbo, unsigned int meshId = 0) const { return genVBO(vbo, meshId, false, false); } // Generates a VBO with // v1.x, v1.y, v1.z, [n1.x, n1.y, n1.z,] [t1.u, t1.v,] v2.x, ... // Note: Querying length and then writing data into pointer works for // both std::vector + glBufferData as well as // glMapBuffer + glUnmapBuffer void genVBO(GLfloat* vbo, unsigned int meshId = 0, bool normals = true, bool texcoords = true) const { assertHasScene(); assert(scene->HasMeshes()); const aiMesh *mesh = scene->mMeshes[meshId]; // calculate stride unsigned int stride = ML_VERTPOS_COUNT; if (normals) { assert(mesh->HasNormals()); stride += ML_NORMAL_COUNT; } if (texcoords) { assert(mesh->HasTextureCoords(0)); stride += ML_TEXCOOR_COUNT; } // copy array and DON'T add 4th component int unsigned n; for (unsigned int i = 0; i < mesh->mNumVertices; ++i) { n = 0; vbo[i*stride+n++] = mesh->mVertices[i].x; vbo[i*stride+n++] = mesh->mVertices[i].y; vbo[i*stride+n++] = mesh->mVertices[i].z; if (normals) { vbo[i*stride+n++] = mesh->mNormals[i].x; vbo[i*stride+n++] = mesh->mNormals[i].y; vbo[i*stride+n++] = mesh->mNormals[i].z; } if (texcoords) { /* TODO: auto-selects first UV(W) channel */ vbo[i*stride+n++] = (mesh->mTextureCoords[0])[i].x; vbo[i*stride+n++] = (mesh->mTextureCoords[0])[i].y; } } } // Generates am index array with v1, v2, v3, v4, v5, v6, ... // to be used with drawElements(GL_TRIANGLES, ...) void genIndexArray(GLuint* vbi, unsigned int meshId = 0) const { assertHasScene(); assert(scene->HasMeshes()); const aiMesh *mesh = scene->mMeshes[meshId]; // copying this whole array takes time, but just referencing it and keeping the other data is worse for (unsigned int i = 0; i < mesh->mNumFaces; ++i) { vbi[i*3+0] = mesh->mFaces[i].mIndices[0]; vbi[i*3+1] = mesh->mFaces[i].mIndices[1]; vbi[i*3+2] = mesh->mFaces[i].mIndices[2]; } } // These return the complete expected length of the buffer object unsigned int lengthOfSimpleVBO(unsigned int meshId = 0) const { return lengthOfVBO(meshId, false, false); } unsigned int lengthOfVBO(unsigned int meshId = 0, bool normals = true, bool texcoords = true) const { assertHasScene(); assert(scene->HasMeshes()); const aiMesh *mesh = scene->mMeshes[meshId]; unsigned int res = mesh->mNumVertices * ML_VERTPOS_COUNT; if (normals) { assert(mesh->HasNormals()); res += mesh->mNumVertices * ML_NORMAL_COUNT; } if (texcoords) { assert(mesh->HasTextureCoords(0)); res += mesh->mNumVertices * ML_TEXCOOR_COUNT; } return res; } unsigned int lengthOfIndexArray(unsigned int meshId = 0) const { assertHasScene(); assert(scene->HasMeshes()); const aiMesh *mesh = scene->mMeshes[meshId]; if (mesh->mNumFaces == 0) { return 0; } return mesh->mNumFaces * mesh->mFaces[0].mNumIndices; } // Returns whether the model has texture coordinates bool hasTextureCoordinates(unsigned int meshId = 0) { assertHasScene(); assert(scene->HasMeshes()); const aiMesh *mesh = scene->mMeshes[meshId]; /* TODO: assumes first UV(W) channel */ return mesh->HasTextureCoords(0); } // Returns whether a model is present bool hasScene() { return _hasScene; } private: void assertHasScene() const { if (!_hasScene) { qWarning() << "No scene available; did you load a model?"; assert(!"no scene loaded"); } } bool _hasScene; const aiScene* scene; Assimp::Importer importer; }; #endif // MODELLOADER_H
AlgoTyc/Computergrafik
skybox.h
#ifndef SKYBOX_H #define SKYBOX_H #include <QOpenGLShaderProgram> #include <QOpenGLFunctions_3_3_Core> class Skybox: QOpenGLFunctions_3_3_Core { public: Skybox(); ~Skybox(); void init_skybox(); void draw(const QMatrix4x4 &projection, QMatrix4x4 view); GLuint handleCubeMap() const { return m_cubeTex; } private: GLuint m_cubeTex; QOpenGLShaderProgram* m_prog_skybox; GLuint m_vbo_skybox; GLuint m_vao_skybox; GLuint m_ibo_skybox; }; #endif // SKYBOX_H
AlgoTyc/Computergrafik
myglwidget.h
<gh_stars>0 #ifndef MYGLWIDGET_H #define MYGLWIDGET_H #include <QOpenGLWidget> #include <QWidget> #include <QKeyEvent> #include <QVector3D> #include <QOpenGLFunctions_3_3_Core> #include <QOpenGLShaderProgram> #include "model.h" #include "skybox.h" #define NUM_LS 5 struct Material { QVector3D ambient; QVector3D diffuse; QVector3D specular; float shininess; }; struct LightSource { alignas(16) QVector3D position; alignas(16) QVector3D color; float ka; float kd; float ks; float constant; float linear; float quadratic; }; class MyGLWidget : public QOpenGLWidget,private QOpenGLFunctions_3_3_Core { Q_OBJECT private: bool m_ortho; int m_FOV=45; int m_Angle; double m_Near=0.1; double m_Far=20.1; int m_RotA; int m_RotB; int m_RotC; QVector3D m_CameraPos=QVector3D(0.0,0.0,-4.0); Model* gimbal; GLuint gw_tex; QOpenGLShaderProgram* m_prog; Model* sphere; Skybox* skybox; bool activateAnimation; bool cameraOnGimbal; QOpenGLShaderProgram* sun_prog; QVector3D m_lightPos=QVector3D(1.0, 1.0, 1.0); Material m_material[4]; LightSource ls[NUM_LS]; unsigned int uboLights; // ubo Handler public: MyGLWidget(QWidget *parent = 0); ~MyGLWidget(); protected: void initializeGL()override; void paintGL()override; void resizeGL(int, int)override; public slots: void setFOV(int); void setAngle(int); void setProjectionMode(bool); void setNear(double); void setFar(double); void setRotationA(int); void setRotationB(int); void setRotationC(int); void diffNearFar(double); void keyPressEvent(QKeyEvent*) override; void setAnimation(bool); void setCameraOnGimbal(bool); signals: void signalDiffNearFar(double); //vC for valueChanged void vCFOV(int); void vCAngle(int); void vCNear(double); void vCFar(double); void vCProjectionMode(bool); void vCRotationA(int); void vCRotationB(int); void vCRotationC(int); void vCAnimation(bool); void vCCOG(bool); }; #endif // MYGLWIDGET_H
AlexKovrigin/PictureCrypt
src/app/model/modelpc.h
#ifndef MODELPC_H #define MODELPC_H #include <QObject> #include <QImage> #include <QByteArray> #include <QColor> #include <QPoint> #include <QVector> #include <QProcess> #include <QTime> #include <QFileInfo> #include <QtGui> #include <QtCore/QRandomGenerator> #include <QPair> #include "qaesencryption.h" #include <QCryptographicHash> /*! \file modelpc.h * Header of ModelPC class * \sa ControllerPC, ModelPC, ViewPC */ /*! * \brief The ModelPC class * Model Layer of the app. * Main class that does the work of PictureCrypt logic * Controled by ControllerPC * \sa ViewPC, ControllerPC * \author <NAME> (waleko) */ class ModelPC : public QObject { Q_OBJECT public: ModelPC(); enum CryptMode {Unspecified, v1_3, v1_4, jphs_mode}; static QImage *Encrypt(QByteArray data, QImage *image, CryptMode _mode, QString key = "", int _bitsUsed = 8, QString *_error = nullptr); static QByteArray Decrypt(QImage * image, QString key, CryptMode _mode = Unspecified, QString *_error = nullptr); signals: /*! * \brief alertView Signal to be called to create MessageBox. * \param messageCode Message Code to be shown. * \param isWarning Flag if message is critical. * \sa ModelPC::alert, ViewPC::alert */ void alertView(QString messageCode, bool isWarning); /*! * \brief saveData Signal to be called to save data from ModelPC::decrypt. * \param data Data to be saved. */ void saveData(QByteArray data); /*! * \brief saveImage Signal to be called to save image from ModelPC::encrypt. * \param image Image to be saved. */ void saveImage(QImage *image); /*! * \brief setProgress Signal to be called to set progress of ProgressDialog. * \param val Value to be set. * \sa ViewPC::setProgress */ void setProgress(int val); public slots: QImage *encrypt(QByteArray data, QImage *image, int _mode, QString key = "", int _bitsUsed = 8, QString *_error = nullptr); QByteArray decrypt(QImage * image, QString key, int _mode = Unspecified, QString *_error = nullptr); void fail(QString message); void alert(QString message, bool isWarning = false); public: QByteArray unzip(QByteArray data, QByteArray key); /*! * \brief success Flag that true by default, * but in case of error or cancelling of ProgressDialog it turns to false, which stops execution of ModelPC::circuit */ bool success; /*! * \brief version Version of the class */ long version; /*! * \brief versionString Version as string */ QString versionString; /*! * \brief defaultJPHSDir Default JPHS directory */ QString defaultJPHSDir; protected: static QImage *Inject(QByteArray encr_data, QImage * image, CryptMode _mode, int _bitsUsed = 8, QString *_error = nullptr); void circuit(QImage * image, QByteArray * data, long long int countBytes); void jphs(QImage * image, QByteArray * data); void processPixel(QPoint pos, QVector<QPoint> *were, bool isEncrypt); void encryptv1_4(QImage *image, QByteArray data, QString key); QByteArray decryptv1_3(QImage * image, QString key); QByteArray decryptv1_4(QImage * image, QString key); void proccessPixelsv1_4(QImage *image, QByteArray* data, QByteArray key, bool isEncrypt, QVector<QPair<QPoint, QPair<int, int> > > *were, long long size = -1); QByteArray zip(QByteArray data, QByteArray key); /*! * \brief error Current error */ QString * error; private: int bitsUsed; bool fileExists(QString path); QByteArray bytes(long long n); unsigned int mod(int input); QByteArray ver_byte; QColor RGBbytes(long long byte); QString generateVersionString(long ver); uint randSeed(); bool isTry = false; QByteArray * circuitData; QImage * circuitImage; long long circuitCountBytes; long cur; bool mustGoOn(bool isEncrypt); QVector <bool> bitsBuffer; long pop(int bits = -1); void push(int data, int bits = -1); void setError(QString word); QByteArray GetRandomBytes(long long count = 32); protected slots: QImage *inject(QByteArray encr_data, QImage * image, int _mode, int _bitsUsed = 8, QString *_error = nullptr); }; #endif // MODELPC_H
AlexKovrigin/PictureCrypt
src/app/view/aboutpc.h
#ifndef ABOUTPC_H #define ABOUTPC_H #include <QDialog> namespace Ui { class AboutPC; } /*! * \brief The AboutPC class The About Page dialog */ class AboutPC : public QDialog { Q_OBJECT public: explicit AboutPC(QWidget *parent = 0); ~AboutPC(); void setVersion(QString version); private: Ui::AboutPC *ui; }; #endif // ABOUTPC_H
AlexKovrigin/PictureCrypt
src/app/view/encryptdialog.h
#ifndef ENCRYPTDIALOG_H #define ENCRYPTDIALOG_H #include <QDialog> #include <QFileDialog> #include <QImage> #include <QMessageBox> #include <QString> #include "../model/qaesencryption.h" #include <QCryptographicHash> namespace Ui { class EncryptDialog; } /*! * \brief The EncryptDialog class Class to get the image and key to store secret info. * \note Not the most important and well written class. * \sa ViewPC */ class EncryptDialog : public QDialog { Q_OBJECT public: explicit EncryptDialog(QByteArray _data, QWidget *parent = 0); ~EncryptDialog(); public slots: void on_fileButton_clicked(); void on_buttonBox_accepted(); void on_buttonBox_rejected(); void on_bitsSlider_valueChanged(int value); public: /*! * \brief data Input data */ QByteArray data; /*! * \brief success Flag, if image was successfully selected and data was encrypted. */ bool success; /*! * \brief compr_data Compressed data, aka Output data. */ QByteArray compr_data; /*! * \brief inputFileName Filename of the image. */ QString inputFileName; /*! * \brief size Size of the image in square pixels */ long long int size; /*! * \brief key Key to be used for encryption in EncrytDialog::zip */ QString key; /*! * \brief goodPercentage Flag if area of the used data via encryption is less than 70% of the area of the image. */ bool goodPercentage; /*! * \brief val Value of the slider */ int val; /*! * \brief bitsUsed Bits used per byte of pixel. * \sa ModelPC::circuit */ int bitsUsed; /*! * \brief image Inputted image */ QImage image; QByteArray zip(); private: Ui::EncryptDialog *ui; void alert(QString text); }; #endif // ENCRYPTDIALOG_H
AlexKovrigin/PictureCrypt
src/app/controllerpc.h
<reponame>AlexKovrigin/PictureCrypt<gh_stars>10-100 #ifndef CONTROLLERPC_H #define CONTROLLERPC_H #include <QObject> #include <QString> #include <QThread> #include <QMessageBox> #include "model/modelpc.h" #include "view/viewpc.h" /*! \file controllerpc.h * Header of ControllerPC class * \sa ControllerPC, ModelPC, ViewPC */ /*! * \brief The ControllerPC class * Controller class, which controls View and Model layers. * \sa ViewPC, ModelPC */ class ControllerPC : public QObject { Q_OBJECT public: ControllerPC(); /*! * \brief version Version of the app */ long int version; /*! * \brief versionString Version of the app as QString. */ QString versionString; public slots: void abortCircuit(); void setJPHSDir(QString dir); private: ViewPC * view; ModelPC * model; }; #endif // CONTROLLERPC_H
AlexKovrigin/PictureCrypt
src/app/view/viewpc.h
<reponame>AlexKovrigin/PictureCrypt #ifndef VIEWPC_H #define VIEWPC_H #include <QMainWindow> #include <QFile> #include <QFileInfo> #include <QFileDialog> #include <QMessageBox> #include <QImage> #include <QByteArray> #include <QVector> #include <QThread> #include <QDesktopServices> #include <QInputDialog> #include <QtMath> #include "encryptdialog.h" #include <QProgressDialog> #include "aboutpc.h" #include <QLocale> namespace Ui { class ViewPC; } /*! \file viewpc.h * Header of ViewPC class * \sa ControllerPC, ModelPC, ViewPC */ /*! * \brief The ViewPC class View layer of the app. * Controls EncryptDialog and ProgressDialog. * \sa ControllerPC, ModelPC, EncryptDialog */ class ViewPC : public QMainWindow { Q_OBJECT public: explicit ViewPC(QWidget *parent = nullptr); ~ViewPC(); private slots: void on_encryptMode_clicked(); void on_decryptMode_clicked(); void on_actionJPHS_path_triggered(); void on_comboBox_currentIndexChanged(int index); void on_text_textChanged(); protected slots: void on_fileButton_clicked(); void on_startButton_clicked(); void on_actionAbout_triggered(); void on_actionHelp_triggered(); void setupErrorsDict(); public slots: void alert(QString message, bool isWarning = false); void saveData(QByteArray Edata); void saveImage(QImage *image); void setProgress(int val); void abortCircuit(); void setEncryptMode(bool encr); void setVersion(QString version); signals: /*! * \brief encrypt Signal calling ModelPC::encrypt * \param data Data to write * \param image Image to be encrypted into * \param mode Mode of encryption * \param key Key of encryption * \param bitsUsed Bits used per byte */ void encrypt(QByteArray data, QImage *image, int mode, QString key, int bitsUsed); /*! * \brief inject Signal calling ModelPC::inject * \param data Data to write * \param image Image to be encrypted into. * \param mode Mode of encryption * \param bitsUsed Bits used per byte */ void inject(QByteArray data, QImage * image, int mode, int bitsUsed); /*! * \brief decrypt Signal calling ModelPC::decrypt * \param _image Image for decryption * \param key encryption key * \param mode Mode of decryption * \sa ModelPC::decrypt, ModelPC::CryptMode */ void decrypt(QImage * _image, QString key, int mode); /*! * \brief abortModel Signal calling to stop ModelPC::circuit */ void abortModel(); /*! * \brief setJPHSPath Sets the default JPHS directory * \param dir Directory */ void setJPHSDir(QString dir); public: /*! * \brief dialog ProgressDialog used. * \sa ViewPC::setProgress, ViewPC::cancel, ModelPC::setProgress */ QProgressDialog * dialog; /*! * \brief progressDialogClosed Flag, if dialog is closed. * \sa ViewPC::abortCircuit, ViewPC::setProgress */ bool progressDialogClosed; /*! * \brief errorsDict QMap - Errors dictionary */ QMap<QString, QString> errorsDict; protected: QString requestKey(); private: Ui::ViewPC *ui; bool isEncrypt; QString inputFileName; QByteArray bytes(long long n); QString versionString; int selectedMode = 2; }; #endif // VIEWPC_H
SaanaVallius/Graphical-UI
GraphicalUI.h
/* * GraphicalGUI.h * * Created on: 12.1.2017 * Author: <NAME> */ #ifndef GRAPHICALUI_H_ #define GRAPHICALUI_H_ #include "LiquidCrystal.h" class GraphicalUI { public: GraphicalUI(); virtual ~GraphicalUI(); void print_auto(); void print_error(); void print_man(); void update_values(int setPressure, int realPressure, int setFanspeed); private: int setPressure; int realPressure; int setFanSpeed; LiquidCrystal *lcd; DigitalIoPin pin_rs; //register select DigitalIoPin pin_en; //enable DigitalIoPin pin_d0; DigitalIoPin pin_d1; DigitalIoPin pin_d2; DigitalIoPin pin_d3; }; #endif /* GRAPHICALUI_H_ */