The examples in this article mainly refer to MSDN: /zh-cn/library/ya9bz4ha%28v=vs.80%
Recently, because the C++ consortium was converted into a C# structure in the project, I checked a lot of information before the conversion was successful.
Note: For the official UNION example, my simple understanding is that this type of UNION practice can be appropriately replaced by operations such as IF ELSE.
Solve the problem: If you only receive video decoded data but never receive audio data, can you directly define the structure and use it to obtain video data.
/// <summary> /// * @struct tagTFrameInfo_YUV420 /// * @brief The decoded frame information structure (including audio and video)/// * @attention If you only receive video decoded data but never receive audio data, then can you directly define the structure and use it to obtain video data/// * @Prototype definition:/// Decoded frame information structure (including audio and video)/// typedef struct tagTFrameInfo /// { /// BYTE m_byMediaType; // Media Type (PCM or YUV420)/// DWORD m_dwTimeStamp; // Timestamp/// union /// { /// BYTE m_byBitCount; // The number of color bits when it is YUV/// BYTE m_bStereo; // is the channel value when PCM/// }; /// union /// { /// WORD m_wVideoWidth; // Video frame width/// WORD m_wBitRate; // Sampling bit rate (such as 8000)/// }; /// union /// { /// WORD m_wVideoHeight;// Video frame width/// WORD m_wBand; // Number of bits sampled (such as 16)/// }; /// }TFrameInfo,*PFrameInfo; /// </summary> [StructLayout()] public struct tagTFrameInfo_YUV420 { /// <summary> /// Media type (0:yuv420; 1:pcm; 2:rgb32: 3:uyvy; 4:YV12), pcm is audio /// @Prototype: BYTE m_byMediaType; // Media type (1:PCM or 0:YUV420) /// </summary> public byte m_byMediaType; /** Media type (0:yuv420; 1:pcm; 2:rgb32: 3:uyvy; 4:YV12), pcm is audio */ /// <summary> /// Time stamp /// @Prototype: DWORD m_dwTimeStamp; // Timestamp /// </summary> public UInt32 m_dwTimeStamp; /** Timestamp */ // YUV /// <summary> /// The number of color bits when YUV is /// @Prototype: BYTE m_byBitCount; //The number of color bits when it is YUV /// </summary> public byte m_byBitCount; /** The number of color bits when YUV */ /// <summary> /// Video frame width /// @Prototype: WORD m_wVideoWidth; //Video frame width /// </summary> public UInt16 m_wVideoWidth; /** Video frame width */ /// <summary> /// Video frame width /// @Prototype: WORD m_wVideoHeight; //Video frame width /// </summary> public UInt16 m_wVideoHeight; /** Video frame width */ }
Interested readers can debug and run this, hoping it will be helpful to everyone.