github.com/cnotch/ipchub@v1.1.0/av/codec/metadata.go (about)

     1  // Copyright (c) 2019,CAOHONGJU All rights reserved.
     2  // Use of this source code is governed by a MIT-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package codec
     6  
     7  // VideoMeta 视频元数据
     8  type VideoMeta struct {
     9  	Codec          string  `json:"codec"`
    10  	Width          int     `json:"width,omitempty"`
    11  	Height         int     `json:"height,omitempty"`
    12  	FixedFrameRate bool    `json:"fixedframerate,omitempty"`
    13  	FrameRate      float64 `json:"framerate,omitempty"`
    14  	DataRate       float64 `json:"datarate,omitempty"`
    15  	ClockRate      int     `json:"clockrate,omitempty"`
    16  	Sps            []byte  `json:"-"`
    17  	Pps            []byte  `json:"-"`
    18  	Vps            []byte  `json:"-"`
    19  
    20  	// // 媒体的参数集,如 sdp中的 sprop_xxx
    21  	// parameterSets `json:"-"`
    22  	// // 不同封装和传输方式的特别参数
    23  	// // 比如 RTP 封装:  streamid, packetization-mode,  profile-level-id 等
    24  	// specificParams `json:"-"`
    25  }
    26  
    27  // AudioMeta 音频元数据
    28  type AudioMeta struct {
    29  	Codec      string  `json:"codec"`
    30  	SampleRate int     `json:"samplerate,omitempty"`
    31  	SampleSize int     `json:"samplesize,omitempty"`
    32  	Channels   int     `json:"channels,omitempty"`
    33  	DataRate   float64 `json:"datarate,omitempty"`
    34  	Sps        []byte  `json:"-"` // sps
    35  
    36  	// // 媒体的参数集,如 sdp中的 sprop_xxx
    37  	// parameterSets `json:"-"`
    38  	// // 不同封装和传输方式的特别参数
    39  	// // 比如 RTP 封装:  streamid, mode, profile-level-id,sizelength, indexlength,indexdeltalength 等
    40  	// specificParams `json:"-"`
    41  }
    42  
    43  type parameterSets [][]byte
    44  
    45  func (pss *parameterSets) ParameterSet(idx int) []byte {
    46  	if len(*pss) <= idx {
    47  		return nil
    48  	}
    49  	return (*pss)[idx]
    50  }
    51  func (pss *parameterSets) SetParameterSet(idx int, paramSet []byte) {
    52  	if len(*pss) <= idx {
    53  		temp := make(parameterSets, idx+1)
    54  		copy(temp, *pss)
    55  		*pss = temp
    56  	}
    57  	(*pss)[idx] = paramSet
    58  }
    59  
    60  type specificParams map[string]string
    61  
    62  func (params *specificParams) SpecificParam(name string) (value string, ok bool) {
    63  	if params == nil {
    64  		return
    65  	}
    66  	value, ok = (*params)[name]
    67  	return
    68  }
    69  
    70  func (params *specificParams) SetSpecificParam(name, value string) {
    71  	if params == nil {
    72  		*params = make(specificParams)
    73  	}
    74  	(*params)[name] = value
    75  }