LibMISB/LibMISB Introduction/ Functionalities supported: Difference between revisions

From RidgeRun Developer Wiki
(Created page with " <noinclude> {{LibMISB/Head|previous=LibMISB_Introduction|next=LibMISB_Introduction/What_does_the_library_do|keywords=}} </noinclude> == LibMISB Overview == Metadata in vi...")
 
No edit summary
 
(38 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<noinclude>
{{LibMISB/Head|previous=LibMISB_Introduction/What_does_the_library_do|next=Supported_Standards/MISB_0601.17|metakeywords=}}
</noinclude>
== General ==
The functionalities of the library, regardless of the standard used, are as follows:
=== Set debug level ===
Sets the level at which messages will be logged.
The method header is:
<syntaxhighlight lang=C>
/**
  * @brief Sets the level for which the messages will be logged
  * The orders from less to most verbose modes are:
  *  LIBMISB_NONE
  *  LIBMISB_ERROR
  *  LIBMISB_WARN
  *  LIBMISB_INFO
  *  LIBMISB_DEBUG
  *
  * @param level Level for messages to be logged
  */
  void SetLogLevel(LogLevel level);
</syntaxhighlight>
'''Use case''':
<syntaxhighlight lang=C>
  libmisb::LibMisb libmisb;
  libmisb.SetLogLevel(LIBMISB_DEBUG);
</syntaxhighlight>
=== Set Formatter ===
Formatter is in charge of assigning which kind of format file (JSON, HTML, etc.) the library will use to receive or deliver the metadata. This library uses the formatter in two cases:
* Encode: this library uses the formatter to parse the incoming metadata (that comes from a specific format file) to metadata object, that stores the standard key and the metadata to encode.
* Decode: this library uses the formatter to deliver to the user the encoded metadata from a KLV package.
In other words, the user chooses which file format to use for both encoding and decoding actions.
{{Ambox
|type=notice
|small=left
|issue='''Important''': before using encode or decode methods you need to set a formatter.
|style=width:unset;
}}
* Composition input format: To encode the input file, it must follow the following structure (a use case will be shown using the JSON format).
<syntaxhighlight lang=json>
{
  "key": "<MISB KEY>",
  "items": [
    {
      "tag": "<TAG NUMBER>",
      "value": "<TAG VALUE>"
    }
  ]
}
</syntaxhighlight>
An example of the previous structure  is:
<syntaxhighlight lang=json>
{
  "key": "060E2B34020B01010E01030101000000",
  "items": [
    {
      "tag": "2",
      "value": "Oct. 24, 2008. 00:13:29.913"
    },
    {
      "tag": "3",
      "value": "MISSION01"
    },
    {
      "tag": "5",
      "value": "159.97436"
    }
  ]
}
</syntaxhighlight>
{{Ambox
|type=notice
|small=left
|issue='''Note''': Some tags are mandatory depending on the standard. In this case, tag 2 is mandatory.
|style=width:unset;
}}


The method header is:
<syntaxhighlight lang=C>
/**
  * @brief Set the Formatter object to convert between format to metadata
  * object and viceversa
  *
  * @param formatter  formatter object that manages the format type that codec
  * will use
  */
  void SetFormatter(std::shared_ptr<libmisb::formatter::iFormatter> formatter);
</syntaxhighlight>


<noinclude>
'''Use case''':
{{LibMISB/Head|previous=LibMISB_Introduction|next=LibMISB_Introduction/What_does_the_library_do|keywords=}}
Remeber to include the formatter header in your code:
</noinclude>
 
<syntaxhighlight lang=C>
#include "libmisb/formatter/jsonformatter.hpp"
</syntaxhighlight>
 
<syntaxhighlight lang=C>
  libmisb::LibMisb libmisb;
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
  libmisb.SetFormatter(json_formatter);
</syntaxhighlight>


=== Encode ===
Performs the encoding of the metadata that was parsed by the Formatter. Encoding will depend on the MISB standard key found in the input file. 
The method header is:
<syntaxhighlight lang=C>
/**
  * @brief Receive string metadata that will convert to KLV
  * bytes in MISB
  *
  * @param data String metadata that is in the formatter format valid
  * @return std::vector<unsigned char> Return KLV bytes in MISB but if there is
  * any internal problem will return empty vector
  */
  std::vector<unsigned char> Encode(std::string data);


</syntaxhighlight>
{{Ambox
|type=notice
|small=left
|issue='''Note''': The formatter must be set, otherwise the encode method will send an error.
|style=width:unset;
}}


== LibMISB Overview ==
'''Use case''':
Metadata in video streams has been used to provide information about streams, audio, or video files. Those metadata could be included on video streaming or as a separate file within a media container; the metadata can include information about the entire video stream, file, or specific frames of the stream.


There is a set of standard specifications defined by the Motion Imagery Standards Board (MISB), where they represent standards for review in the area of Motion Imagery, as well as associated metadata and multimedia. Put another way, MISB standards define how metadata should be processed before being sent to a receiver, or received by a sender. Importantly, this standard uses the Key-Length-Value (KLV) data encoding protocol.
<syntaxhighlight lang=C>
  libmisb::LibMisb libmisb;
  // Remember to set formatter
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
  libmisb.SetFormatter(json_formatter);
  std::vector<unsigned char> packet_encoded = libmisb.Encode(data);
</syntaxhighlight>


== Key Length Value (KLV) Metadata  ==
=== Decode ===
KLV data is any binary data that we need to move from one end to the other while keeping the data associated with the correct video frame. It is up to the user of the video encoding stream and the user of the video decoding stream to understand the meaning and encoding of the KLV data.
Performs decoding of the metadata found in a KLV byte packet. The decoding will depend on the MISB standard key found in the packet. Once decoded, it will return the data according to the configured format type.
The method header is:
<syntaxhighlight lang=C>
/**
  * @brief  Receive packet encoded metadata that will convert to the formatter
  * format in MISB
  *
  * @param packet Vector with encoded metadata
  * @return std::string Return string with metadata decoded
  */
  std::string Decode(std::vector<unsigned char> packet);
</syntaxhighlight>


To give a concrete KLV encoding example, here is a terse description of the SMPTE 336M-2007 Data Encoding Protocol using Key-Length Value, which is used by MISB standard.
{{Ambox
{| border=2
|type=notice
! Key !! Length !! Value
|small=left
|-
|issue='''Note''': The formatter must be set, otherwise the decode method will send an error.
|  
|style=width:unset;
Fixed length (1, 2, 4, or 16 bytes), size known to both sender and receiver, encoding the key.  There are very specific rules on how keys are encoded and how both, the sender and receiver, know the meaning of the encoded key.
}}
||
Fixed or variable length (1, 2, 4, or BER) indication of the number of bytes of data used to encode the value.
||
Variable length value whose meaning is agreed to by both the sender and the receiver.
|}


As an example (from [http://en.wikipedia.org/wiki/KLV Wikipedia KLV entry]),
'''Use case''':


{| border=2 align="center"
<syntaxhighlight lang=C>
|-
  libmisb::LibMisb libmisb;
! Key
  // Remember to set formatter
! Length
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
!colspan="2"| Value
  libmisb.SetFormatter(json_formatter);
|-
  std::string data_decoded = libmisb.Decode(packet);
| 42
</syntaxhighlight>
| 2
| 0
| 3
|}


Which could be passed in as a 4-byte binary blob of 0x2A 0x02 0x00 0x03.  The transport of the KLV doesn't need to know the actual encoding, just that it is 4 bytes long and the actual KLV data.


As another example (not MISB compliant), you could have the length be 8 and the data be 0x46 0x4F 0x4F 0x3D 0x42 0x41 0x52 0x00, which works out to be the NULL-terminated ASCII string ''FOO=BAR''.  The transport doesn't care about the encoding, just so both the sending and receiver are in agreement.


== Motion Imagery Standards Board (MISB) ==
<noinclude>{{LibMISB/Foot|LibMISB_Introduction/What_does_the_library_do|Supported_Standards/MISB_0601.17}}</noinclude>
This project provides the support of MISB standards that comply with the KLV protocol. Allows users to easily manipulate their encode and decode depending on MISB standards. If you want more information about MISB standards, please follow the next link  [https://nsgreg.nga.mil/misb.jsp Motion Imagery Standards Board (MISB)].

Latest revision as of 15:15, 28 August 2024



Previous: LibMISB_Introduction/What_does_the_library_do Index Next: Supported_Standards/MISB_0601.17





General

The functionalities of the library, regardless of the standard used, are as follows:

Set debug level

Sets the level at which messages will be logged. The method header is:

/**
   * @brief Sets the level for which the messages will be logged
   * The orders from less to most verbose modes are:
   *  LIBMISB_NONE
   *  LIBMISB_ERROR
   *  LIBMISB_WARN
   *  LIBMISB_INFO
   *  LIBMISB_DEBUG
   *
   * @param level Level for messages to be logged
   */
  void SetLogLevel(LogLevel level);

Use case:

  libmisb::LibMisb libmisb;
  libmisb.SetLogLevel(LIBMISB_DEBUG);

Set Formatter

Formatter is in charge of assigning which kind of format file (JSON, HTML, etc.) the library will use to receive or deliver the metadata. This library uses the formatter in two cases:

  • Encode: this library uses the formatter to parse the incoming metadata (that comes from a specific format file) to metadata object, that stores the standard key and the metadata to encode.
  • Decode: this library uses the formatter to deliver to the user the encoded metadata from a KLV package.

In other words, the user chooses which file format to use for both encoding and decoding actions.

  • Composition input format: To encode the input file, it must follow the following structure (a use case will be shown using the JSON format).
{ 
  "key": "<MISB KEY>",
  "items": [
    {
      "tag": "<TAG NUMBER>",
      "value": "<TAG VALUE>"
    }
  ]
}

An example of the previous structure is:

{ 
  "key": "060E2B34020B01010E01030101000000",
  "items": [
    {
      "tag": "2",
      "value": "Oct. 24, 2008. 00:13:29.913"
    },
    {
      "tag": "3",
      "value": "MISSION01"
    },
    {
      "tag": "5",
      "value": "159.97436"
    }
  ]
}

The method header is:

/**
   * @brief Set the Formatter object to convert between format to metadata
   * object and viceversa
   *
   * @param formatter  formatter object that manages the format type that codec
   * will use
   */
  void SetFormatter(std::shared_ptr<libmisb::formatter::iFormatter> formatter);

Use case: Remeber to include the formatter header in your code:

#include "libmisb/formatter/jsonformatter.hpp"
  libmisb::LibMisb libmisb;
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
  libmisb.SetFormatter(json_formatter);

Encode

Performs the encoding of the metadata that was parsed by the Formatter. Encoding will depend on the MISB standard key found in the input file.

The method header is:

/**
   * @brief Receive string metadata that will convert to KLV
   * bytes in MISB
   *
   * @param data String metadata that is in the formatter format valid
   * @return std::vector<unsigned char> Return KLV bytes in MISB but if there is
   * any internal problem will return empty vector
   */
  std::vector<unsigned char> Encode(std::string data);

Use case:

  libmisb::LibMisb libmisb;
  // Remember to set formatter
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
  libmisb.SetFormatter(json_formatter);
  std::vector<unsigned char> packet_encoded = libmisb.Encode(data);

Decode

Performs decoding of the metadata found in a KLV byte packet. The decoding will depend on the MISB standard key found in the packet. Once decoded, it will return the data according to the configured format type. The method header is:

/**
   * @brief  Receive packet encoded metadata that will convert to the formatter
   * format in MISB
   *
   * @param packet Vector with encoded metadata
   * @return std::string Return string with metadata decoded
   */
  std::string Decode(std::vector<unsigned char> packet);

Use case:

  libmisb::LibMisb libmisb;
  // Remember to set formatter
  std::shared_ptr<libmisb::formatter::iFormatter> json_formatter = std::make_shared<libmisb::formatter::JsonFormatter>();
  libmisb.SetFormatter(json_formatter);
  std::string data_decoded = libmisb.Decode(packet);



Previous: LibMISB_Introduction/What_does_the_library_do Index Next: Supported_Standards/MISB_0601.17