rtsp_sink.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*************************************************************************
  2. * Copyright (C) [2019] by Cambricon, Inc. All rights reserved
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * The above copyright notice and this permission notice shall be included in
  11. * all copies or substantial portions of the Software.
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  13. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  15. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. * THE SOFTWARE.
  19. *************************************************************************/
  20. #ifndef MODULES_RTSP_SINK_INCLUDE_RTSP_SINK_HPP_
  21. #define MODULES_RTSP_SINK_INCLUDE_RTSP_SINK_HPP_
  22. #include <memory>
  23. #include <mutex>
  24. #include <set>
  25. #include <string>
  26. #include <unordered_map>
  27. #include "cnstream_frame.hpp"
  28. #include "cnstream_module.hpp"
  29. #include "cnstream_frame_va.hpp"
  30. #include "private/cnstream_param.hpp"
  31. #include "video/video_stream/video_stream.hpp"
  32. namespace cnstream {
  33. using CNFrameInfoPtr = std::shared_ptr<CNFrameInfo>;
  34. struct RtspSinkContext;
  35. struct RtspSinkParam;
  36. /**
  37. * @brief RtspSink is a module to deliver stream by RTSP protocol
  38. */
  39. class RtspSink : public Module, public ModuleCreator<RtspSink> {
  40. public:
  41. /**
  42. * @brief RtspSink constructor
  43. *
  44. * @param name : module name
  45. */
  46. explicit RtspSink(const std::string& name);
  47. /**
  48. * @brief RtspSink destructor
  49. */
  50. ~RtspSink();
  51. /**
  52. * @brief Called by pipeline when pipeline start.
  53. *
  54. * @param paramSet : parameter set
  55. *
  56. * @return ture if module open succeed, otherwise false.
  57. */
  58. bool Open(ModuleParamSet paramSet) override;
  59. /**
  60. * @brief Called by pipeline when pipeline stop
  61. */
  62. void Close() override;
  63. /**
  64. * @brief Encode each frame
  65. *
  66. * @param data : data to be processed
  67. *
  68. * @return whether process succeed
  69. * @retval 0: succeed and do no intercept data
  70. * @retval <0: failed
  71. */
  72. int Process(CNFrameInfoPtr data) override;
  73. void OnEos(const std::string &stream_id) override;
  74. private:
  75. RtspSinkContext * GetContext(CNFrameInfoPtr data);
  76. RtspSinkContext * CreateContext(CNFrameInfoPtr data, const std::string &stream_id);
  77. ModuleParamsHelper<RtspSinkParam>* param_helper_ = nullptr;
  78. int stream_index_ = 0;
  79. std::mutex ctx_lock_;
  80. std::unordered_map<std::string, RtspSinkContext *> contexts_;
  81. std::set<std::string> tile_streams_;
  82. }; // class RtspSink
  83. } // namespace cnstream
  84. #endif // MODULES_RTSP_SINK_INCLUDE_RTSP_SINK_HPP_