1 /* 2 * Copyright (C) 2019 The Android Open Source Project 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 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <string> 20 #include <vector> 21 22 struct SDP { 23 explicit SDP(); 24 25 int initCheck() const; 26 27 void clear(); 28 int setTo(const std::string &data); 29 30 // Section 0 is reserved for top-level attributes, section indices >= 1 31 // correspond to each media section starting with an "m=" line. 32 size_t countSections() const; 33 34 std::vector<std::string>::const_iterator section_begin( 35 size_t section) const; 36 37 std::vector<std::string>::const_iterator section_end( 38 size_t section) const; 39 40 struct SectionEditor { 41 ~SectionEditor(); 42 43 SectionEditor &operator<<(std::string_view s); 44 45 void commit(); 46 47 private: 48 friend struct SDP; 49 50 explicit SectionEditor(SDP *sdp, size_t section); 51 52 SDP *mSDP; 53 size_t mSection; 54 55 std::string mBuffer; 56 }; 57 58 SectionEditor createSection(); 59 SectionEditor appendToSection(size_t section); 60 61 static void Test(); 62 63 private: 64 int mInitCheck; 65 std::vector<std::string> mLines; 66 67 std::vector<size_t> mLineIndexBySection; 68 69 bool mNewSectionEditorActive; 70 71 void getSectionRange( 72 size_t section, 73 size_t *lineStartIndex, 74 size_t *lineStopIndex) const; 75 76 void commitSectionEdit( 77 size_t section, const std::vector<std::string> &lines); 78 }; 79 80