-
Notifications
You must be signed in to change notification settings - Fork 7
Add ARCHITECTURE.md and PRODUCT.md documentation #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anand-ky
wants to merge
2
commits into
develop
Choose a base branch
from
feature/add-architecture-product-docs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,223 @@ | ||
| # HDMI-CEC Library Architecture | ||
|
|
||
| ## Overview | ||
|
|
||
| The HDMI-CEC library is a C++ implementation for managing HDMI Consumer Electronics Control (CEC) protocol communications on RDK (Reference Design Kit) platforms. This library provides a layered architecture that abstracts hardware-specific CEC driver implementations and offers high-level APIs for CEC message processing. | ||
|
|
||
| ## High-Level Architecture | ||
|
|
||
| The library follows a three-layer architecture: | ||
|
|
||
| ``` | ||
| ┌─────────────────────────────────────────────────────┐ | ||
| │ Application Layer │ | ||
| │ (Uses Connection & MessageProcessor APIs) │ | ||
| └─────────────────────────────────────────────────────┘ | ||
| ↓ | ||
| ┌─────────────────────────────────────────────────────┐ | ||
| │ CCEC Layer (Core CEC Logic) │ | ||
| │ - Connection Management │ | ||
| │ - Message Encoding/Decoding │ | ||
| │ - Bus Communication │ | ||
| │ - Frame Processing │ | ||
| └─────────────────────────────────────────────────────┘ | ||
| ↓ | ||
| ┌─────────────────────────────────────────────────────┐ | ||
| │ OSAL Layer │ | ||
| │ (OS Abstraction - Threading, Synchronization) │ | ||
| └─────────────────────────────────────────────────────┘ | ||
| ↓ | ||
| ┌─────────────────────────────────────────────────────┐ | ||
| │ Driver Layer │ | ||
| │ (Hardware-specific CEC Driver Interface) │ | ||
| └─────────────────────────────────────────────────────┘ | ||
| ``` | ||
|
|
||
| ## Core Components | ||
|
|
||
| ### 1. OSAL (OS Abstraction Layer) | ||
|
|
||
| **Location:** `osal/` | ||
|
|
||
| Provides platform-independent synchronization primitives and utilities: | ||
|
|
||
| - **Thread**: POSIX thread wrapper for concurrent execution | ||
| - **Mutex**: Mutual exclusion for thread-safe operations | ||
| - **ConditionVariable**: Thread synchronization mechanism | ||
| - **EventQueue**: Thread-safe event queue for asynchronous processing | ||
| - **Runnable/Stoppable**: Interfaces for thread lifecycle management | ||
|
|
||
| **Key Features:** | ||
| - Platform abstraction for portability | ||
| - Thread-safe container implementations | ||
| - Exception-based error handling | ||
|
|
||
| ### 2. CCEC (Core CEC Implementation) | ||
|
|
||
| **Location:** `ccec/` | ||
|
|
||
| The main CEC protocol implementation with several key subsystems: | ||
|
|
||
| #### 2.1 Connection Management | ||
|
|
||
| **Classes:** `Connection`, `Bus` | ||
|
|
||
| - **Connection**: Primary API for applications to access the CEC bus | ||
| - Manages logical addresses (source/destination) | ||
| - Provides send/receive operations for CEC frames | ||
| - Supports both synchronous and asynchronous messaging | ||
| - Implements frame listener registration | ||
|
|
||
| - **Bus**: Singleton managing the physical CEC bus | ||
| - Routes frames between connections and the driver | ||
| - Manages frame listeners | ||
| - Handles polling and device discovery | ||
| - Thread-safe operation using OSAL primitives | ||
|
|
||
| #### 2.2 Message Processing | ||
|
|
||
| **Classes:** `MessageEncoder`, `MessageDecoder`, `MessageProcessor` | ||
|
|
||
| - **MessageEncoder**: Converts high-level message objects to raw CEC frames | ||
| - **MessageDecoder**: Parses raw CEC frames into message objects | ||
| - **MessageProcessor**: Base class with virtual methods for processing specific CEC messages | ||
| - Implements visitor pattern for message handling | ||
| - Applications extend this to handle specific message types | ||
| - Default implementation discards messages (acts as filter) | ||
|
|
||
| **Supported Message Types:** | ||
| - Active Source / Inactive Source | ||
| - Image View On / Text View On | ||
| - Standby, Power Status | ||
| - Routing Control (Set Stream Path, Routing Change, etc.) | ||
| - OSD Name, Vendor Commands | ||
| - Device capabilities (CEC Version, Physical Address) | ||
|
|
||
| #### 2.3 Frame and Data Management | ||
|
|
||
| **Classes:** `CECFrame`, `Header`, `OpCode`, `Operands` | ||
|
|
||
| - **CECFrame**: Raw byte buffer representing complete CEC messages | ||
| - Header block (initiator/destination addresses) | ||
| - OpCode block (message type) | ||
| - Operand block (message parameters) | ||
|
|
||
| - **Header**: Encapsulates source and destination logical addresses | ||
| - **OpCode**: Defines all CEC operation codes | ||
| - **Operands**: Container for message-specific parameters | ||
|
|
||
| #### 2.4 Driver Interface | ||
|
|
||
| **Classes:** `Driver`, `DriverImpl` | ||
|
|
||
| - **Driver**: Abstract interface for hardware CEC driver | ||
| - `open()`, `close()`: Resource management | ||
| - `read()`, `write()`: Frame I/O operations | ||
| - `poll()`: Device presence detection | ||
| - Singleton pattern for system-wide access | ||
|
|
||
| - **DriverImpl**: Concrete implementation | ||
| - Callbacks for asynchronous receive/transmit | ||
| - Incoming frame queue management | ||
| - State machine for driver lifecycle (CLOSED/OPENING/OPENED/CLOSING) | ||
| - ACK/NACK handling (SENT_AND_ACKD, SENT_FAILED, SENT_BUT_NOT_ACKD) | ||
|
|
||
| #### 2.5 Host Integration | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not used we can remove from code and the docs |
||
|
|
||
| **Interface:** `Host.hpp` | ||
|
|
||
| C-compatible API for platform-specific host implementations: | ||
|
|
||
| - Device status monitoring (power state, connection, OSD name) | ||
| - Policy management (TV/STB power control) | ||
| - Callback mechanisms for host notifications | ||
| - Error code definitions | ||
|
|
||
| ## Communication Flow | ||
|
|
||
| ### Sending Messages | ||
|
|
||
| ``` | ||
| Application | ||
| ↓ creates Message object | ||
| MessageEncoder | ||
| ↓ encode to CECFrame | ||
| Connection | ||
| ↓ send() or sendAsync() | ||
| Bus | ||
| ↓ queue and route | ||
| Driver | ||
| ↓ transmit to hardware | ||
| CEC Bus | ||
| ``` | ||
|
|
||
| ### Receiving Messages | ||
|
|
||
| ``` | ||
| CEC Bus | ||
| ↓ hardware interrupt | ||
| Driver (DriverReceiveCallback) | ||
| ↓ enqueue CECFrame | ||
| Bus | ||
| ↓ notify listeners | ||
| FrameListener(s) | ||
| ↓ filter and process | ||
| MessageDecoder | ||
| ↓ decode to Message object | ||
| MessageProcessor | ||
| ↓ process() method | ||
| Application | ||
| ``` | ||
|
|
||
| ## Design Patterns | ||
|
|
||
| 1. **Singleton Pattern**: `Bus`, `Driver` - ensures single instance per system | ||
| 2. **Observer Pattern**: `FrameListener`, `FrameFilter` - event notification | ||
| 3. **Factory Pattern**: Message creation through encoder/decoder | ||
| 4. **Strategy Pattern**: `MessageProcessor` - pluggable message handling | ||
| 5. **Template Pattern**: OSAL abstractions for platform independence | ||
|
|
||
| ## Thread Safety | ||
|
|
||
| - All public APIs are thread-safe using OSAL Mutex | ||
| - Bus uses internal locking for listener management | ||
| - Driver callbacks execute on separate threads | ||
| - EventQueue provides thread-safe message queuing | ||
| - Asynchronous operations recommended to avoid blocking | ||
|
|
||
| ## Build System | ||
|
|
||
| - **Autotools-based**: `configure.ac`, `Makefile.am` | ||
| - **Dependencies**: glib-2.0 (≥0.10.28) | ||
| - **Subdirectories**: cfg, osal, ccec, tests | ||
| - **Output**: Shared libraries for OSAL and CCEC components | ||
| - **Build scripts**: `build.sh`, `rdk_build.sh` for RDK integration | ||
|
|
||
| ## Testing | ||
|
|
||
| **Location:** `tests/` | ||
|
|
||
| - **BasicTest.cpp**: Fundamental API validation | ||
| - **CECCmdTest.cpp**: Command processing tests | ||
| - **CECMonitor.cpp**: Bus monitoring utility | ||
|
|
||
| ## Key Design Decisions | ||
|
|
||
| 1. **Asynchronous-First**: Library prioritizes async operations due to CEC's inherent latency and unreliable device responses | ||
| 2. **Layered Abstraction**: OSAL enables portability across platforms | ||
| 3. **Type-Safe Messages**: C++ classes for each message type prevent errors | ||
| 4. **Extensible Processing**: Virtual methods allow custom message handling | ||
| 5. **Exception-Based Errors**: Uses exceptions for error propagation in critical paths | ||
|
|
||
| ## Extension Points | ||
|
|
||
| Applications can extend the library by: | ||
|
|
||
| 1. Implementing custom `MessageProcessor` subclasses | ||
| 2. Creating custom `FrameListener` implementations | ||
| 3. Implementing platform-specific `Driver` backends | ||
| 4. Extending host integration callbacks | ||
|
|
||
| ## Version | ||
|
|
||
| Current version: 1.0.7 (as per CHANGELOG.md) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should remove OSAL as it is giving impression that that layer is making HAL call however it is abstracting mutex and thread related calls