@@ -44,27 +44,90 @@ class Decoder
4444
4545 Decoder ();
4646 ~Decoder ();
47+ /* *
48+ * Test if decoder is initialized.
49+ * @return true if the decoder is initialized.
50+ */
4751 bool isInitialized () const { return (codecContext_ != NULL ); }
48- // Initialize decoder upon first packet received,
49- // providing callback to be called when frame is complete.
50- // You must still call decodePacket(msg) afterward!
51- bool initialize (const std::string & encoding, Callback callback, const std::string & dec);
52- // clears all state, but leaves config intact
52+ /* *
53+ * Initialize decoder, with multiple decoders to pick from.
54+ * Will pick hardware accelerated decoders first if available.
55+ * If decoders.empty() a default decoder will be chosen (if available).
56+ * @param encoding the encoding from the first packet. Can never change!
57+ * @param callback the function to call when frame has been decoded
58+ * @param decoder the decoder to use. If empty string,
59+ * the decoder will try to find a suitable one based on the encoding
60+ * @return true if successful
61+ */
62+
63+ bool initialize (const std::string & encoding, Callback callback, const std::string & decoder);
64+ /* *
65+ * Initialize decoder with multiple decoders to pick from.
66+ * Will pick hardware accelerated decoders first if available.
67+ * If decoders.empty() a default decoder will be chosen (if available).
68+ * @param encoding the encoding from the first packet. Can never change!
69+ * @param callback the function to call when frame has been decoded
70+ * @param decoders the set of decoders to try sequentially. If empty()
71+ * the decoder will try to find a suitable one based on the encoding
72+ * @return true if successful
73+ */
74+ bool initialize (
75+ const std::string & encoding, Callback callback, const std::vector<std::string> & decoders);
76+ /* *
77+ * Clears all decoder state but not timers, loggers, and other settings.
78+ */
5379 void reset ();
54- // decode packet (may result in frame callback!)
80+ /* *
81+ * Decodes packet. Decoder must have been initialized beforehand. Calling this
82+ * function may result in callback with decoded frame.
83+ * @param encoding the name of the encoding (typically from msg encoding)
84+ * @param data pointer to packet data
85+ * @param size size of packet data
86+ * @param pts presentation time stamp of data packet
87+ * @param frame_id ros frame id (from message header)
88+ * @param stamp ros message header time stamp
89+ */
5590 bool decodePacket (
5691 const std::string & encoding, const uint8_t * data, size_t size, uint64_t pts,
5792 const std::string & frame_id, const rclcpp::Time & stamp);
58-
93+ /* *
94+ * Override default logger
95+ * @param logger the logger to override the default with
96+ */
97+ void setLogger (rclcpp::Logger logger) { logger_ = logger; }
98+ /* *
99+ * deprecated, don't use!
100+ */
101+ static const std::unordered_map<std::string, std::string> & getDefaultEncoderToDecoderMap ();
102+ /* *
103+ * Finds the name of hardware and software decoders that match a
104+ * certain encoding (or encoder)
105+ */
106+ static void findDecoders (
107+ const std::string & encoding, std::vector<std::string> * hw_decoders,
108+ std::vector<std::string> * sw_decoders);
109+ /* *
110+ * Finds the name of all hardware and software decoders that match
111+ * a certain encoding (or encoder)
112+ */
113+ static std::vector<std::string> findDecoders (const std::string & encoding);
114+ /* *
115+ * For performance debugging
116+ */
59117 void setMeasurePerformance (bool p) { measurePerformance_ = p; }
118+ /* *
119+ * For performance debugging
120+ */
60121 void printTimers (const std::string & prefix) const ;
122+ /* *
123+ * For performance debugging
124+ */
61125 void resetTimers ();
62- void setLogger (rclcpp::Logger logger) { logger_ = logger; }
63- static const std::unordered_map<std::string, std::string> & getDefaultEncoderToDecoderMap ();
64126
65127private:
66128 rclcpp::Logger logger_;
67- bool initDecoder (const std::string & encoding, const std::string & decoder);
129+ bool initSingleDecoder (const std::string & decoder);
130+ bool initDecoder (const std::vector<std::string> & decoders);
68131 // --------------- variables
69132 Callback callback_;
70133 PTSMap ptsToStamp_; // mapping of header
0 commit comments