text: //----------------------------------------------------------------------------
  //
  // TSDuck - The MPEG Transport Stream Toolkit
  // Copyright (c) 2005-2020, Thierry Lelegard
  // All rights reserved.
  //
  // Redistribution and use in source and binary forms, with or without
  // modification, are permitted provided that the following conditions are met:
  //
  // 1. Redistributions of source code must retain the above copyright notice,
  //    this list of conditions and the following disclaimer.
  // 2. Redistributions in binary form must reproduce the above copyright
  //    notice, this list of conditions and the following disclaimer in the
  //    documentation and/or other materials provided with the distribution.
  //
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  // THE POSSIBILITY OF SUCH DAMAGE.
  //
  //----------------------------------------------------------------------------
  
  #include "tsStreamModeDescriptor.h"
  #include "tsDescriptor.h"
  #include "tsTablesDisplay.h"
  #include "tsPSIRepository.h"
  #include "tsPSIBuffer.h"
  #include "tsDuckContext.h"
  #include "tsxmlElement.h"
  #include "tsNames.h"
  TSDUCK_SOURCE;
  
  #define MY_XML_NAME u"stream_mode_descriptor"
  #define MY_CLASS ts::StreamModeDescriptor
  #define MY_DID ts::DID_STREAM_MODE
  #define MY_STD ts::Standards::MPEG
  
  TS_REGISTER_DESCRIPTOR(MY_CLASS, ts::EDID::Standard(MY_DID), MY_XML_NAME, MY_CLASS::DisplayDescriptor);
  
  
  //----------------------------------------------------------------------------
  // Constructors
  //----------------------------------------------------------------------------
  
  ts::StreamModeDescriptor::StreamModeDescriptor(uint8_t mode) :
      AbstractDescriptor(MY_DID, MY_XML_NAME, MY_STD, 0),
      stream_mode(mode)
  {
  }
  
  ts::StreamModeDescriptor::StreamModeDescriptor(DuckContext& duck, const Descriptor& desc) :
      StreamModeDescriptor()
  {
      deserialize(duck, desc);
  }
  
  void ts::StreamModeDescriptor::clearContent()
  {
      stream_mode = 0;
  }
  
  
  //----------------------------------------------------------------------------
  // Serialization / deserialization.
  //----------------------------------------------------------------------------
  
  void ts::StreamModeDescriptor::serializePayload(PSIBuffer& buf) const
  {
      buf.putUInt8(stream_mode);
      buf.putUInt8(0xFF); // reserved
  }
  
  void ts::StreamModeDescriptor::deserializePayload(PSIBuffer& buf)
  {
      stream_mode = buf.getUInt8();
      buf.skipBits(8);
  }
  
  
  //----------------------------------------------------------------------------
  // Static method to display a descriptor.
  //----------------------------------------------------------------------------
  
  void ts::StreamModeDescriptor::DisplayDescriptor(TablesDisplay& disp, PSIBuffer& buf, const UString& margin, DID did, TID tid, PDS pds)
  {
      if (buf.canReadBytes(2)) {
          disp << margin << UString::Format(u"Stream mode: %s", {NameFromSection(u"DSMCCStreamMode", buf.getUInt8(), names::HEXA_FIRST)}) << std::endl;
          buf.skipBits(8);
      }
  }
  
  
  //----------------------------------------------------------------------------
  // XML serialization / deserialization.
  //----------------------------------------------------------------------------
  
  void ts::StreamModeDescriptor::buildXML(DuckContext& duck, xml::Element* root) const
  {
      root->setIntAttribute(u"stream_mode", stream_mode, true);
  }
  
  bool ts::StreamModeDescriptor::analyzeXML(DuckContext& duck, const xml::Element* element)
  {
      return element->getIntAttribute(stream_mode, u"stream_mode", true);
  }
  