• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef I_STREAM_DATA_H
17 #define I_STREAM_DATA_H
18 
19 #include <cstdint>
20 #include <memory>
21 #include <sys/types.h>
22 
23 #include "stream_common.h"
24 
25 namespace Communication {
26 namespace SoftBus {
27 struct StreamData {
28     std::unique_ptr<char[]> buffer = nullptr;
29     ssize_t bufLen = 0;
30     std::unique_ptr<char[]> extBuffer = nullptr;
31     ssize_t extLen = 0;
32 };
33 
34 // APP should update StreamFrameInfo each time.
35 struct StreamFrameInfo {
36     uint32_t streamId = 0;
37     uint32_t seqNum = 0;
38     uint32_t level = 0;
39     FrameType frameType = NONE;
40     uint32_t timestamp = 0;
41     uint32_t bitrate = 0;
42 };
43 
44 class IStream {
45 public:
46     IStream() = default;
47     virtual ~IStream() = default;
48 
49     static std::unique_ptr<IStream> MakeCommonStream(StreamData &data, const StreamFrameInfo &info);
50     static std::unique_ptr<IStream> MakeSliceStream(StreamData &data, const StreamFrameInfo &info);
51     static std::unique_ptr<IStream> MakeRawStream(StreamData &data, const StreamFrameInfo &info);
52     static std::unique_ptr<IStream> MakeRawStream(const char *buf, ssize_t bufLen, const StreamFrameInfo &info,
53         int scene);
54 
55     virtual void SetTimeStamp(uint32_t timestamp) = 0;
56     virtual uint32_t GetTimeStamp() const = 0;
57 
58     virtual std::unique_ptr<char[]> GetBuffer() = 0;
59     virtual ssize_t GetBufferLen() const = 0;
60     virtual std::unique_ptr<char[]> GetExtBuffer() = 0;
61     virtual ssize_t GetExtBufferLen() const = 0;
62 
63     virtual int GetSeqNum() const = 0;
64     virtual uint32_t GetStreamId() const = 0;
65 };
66 }; // namespace SoftBus
67 }; // namespace Communication
68 
69 #endif