支持了实际类型显示,优化dbopen

This commit is contained in:
2024-09-16 23:21:27 +08:00
parent e3609aab14
commit 823d0a871d
4 changed files with 252 additions and 37 deletions

View File

@@ -15,8 +15,8 @@ func TestGetBDVersion(t *testing.T) {
}
func TestBD(t *testing.T) {
db := BDOpen("path")
if db == nil {
db, err := BDOpen("path")
if err != nil {
t.Errorf("Expected non-nil DBStruct, got nil")
return
}

View File

@@ -8,6 +8,7 @@ package bluray
import "C"
import (
"fmt"
"os"
"strconv"
"strings"
"unsafe"
@@ -24,11 +25,15 @@ type DBStruct struct {
}
// BDOpen 打开蓝光光盘
func BDOpen(path string) *DBStruct {
func BDOpen(path string) (*DBStruct, error) {
// 检查文件路径是否存在文件或者文件夹
if _, err := os.Stat(path); err != nil {
return nil, fmt.Errorf("file not found: %v", err)
}
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
return &DBStruct{bd: C.bd_open(cPath, nil)}
return &DBStruct{bd: C.bd_open(cPath, nil)}, nil
}
// GetDiscInfo 获取蓝光光盘信息
@@ -174,7 +179,7 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
clipInfo := BlurayClipInfo{
PktCount: uint32(cClip.pkt_count),
StillMode: uint8(cClip.still_mode),
StillMode: getStillModeString(cClip.still_mode),
StillTime: uint16(cClip.still_time),
VideoStreamCount: uint8(cClip.video_stream_count),
AudioStreamCount: uint8(cClip.audio_stream_count),
@@ -196,12 +201,12 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
cStream := cVideoStreams[j]
lang := getLanguageCode(cStream.lang)
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CodingType: getCodingString(cStream.coding_type),
Format: getVideoFormatString(cStream.format),
Rate: getVideoRateString(cStream.rate),
CharCode: uint8(cStream.char_code),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
Aspect: getAspectRatioString(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: lang,
}
@@ -217,12 +222,11 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
cStream := cAudioStreams[j]
lang := getLanguageCode(cStream.lang)
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CodingType: getCodingString(cStream.coding_type),
Format: getAudioFormatString(cStream.format),
Rate: getAudioRateString(cStream.rate),
CharCode: uint8(cStream.char_code),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: lang,
}
@@ -237,12 +241,8 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
for j := 0; j < int(cClip.pg_stream_count); j++ {
cStream := cPgStreams[j]
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CharCode: uint8(cStream.char_code),
CodingType: getCodingString(cStream.coding_type),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: C.GoStringN((*C.char)(unsafe.Pointer(&cStream.lang[0])), 3),
}
@@ -257,12 +257,8 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
for j := 0; j < int(cClip.ig_stream_count); j++ {
cStream := cIgStreams[j]
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CharCode: uint8(cStream.char_code),
CodingType: getCodingString(cStream.coding_type),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: C.GoStringN((*C.char)(unsafe.Pointer(&cStream.lang[0])), 3),
}
@@ -277,12 +273,10 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
for j := 0; j < int(cClip.sec_audio_stream_count); j++ {
cStream := cSecAudioStreams[j]
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CharCode: uint8(cStream.char_code),
CodingType: getCodingString(cStream.coding_type),
Format: getAudioFormatString(cStream.format),
Rate: getAudioRateString(cStream.rate),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: C.GoStringN((*C.char)(unsafe.Pointer(&cStream.lang[0])), 3),
}
@@ -297,12 +291,12 @@ func (d *DBStruct) GetTitleInfo(titleIdx uint32, angle uint) (*BlurayTitleInfo,
for j := 0; j < int(cClip.sec_video_stream_count); j++ {
cStream := cSecVideoStreams[j]
streamInfo := BlurayStreamInfo{
CodingType: uint8(cStream.coding_type),
Format: uint8(cStream.format),
Rate: uint8(cStream.rate),
CodingType: getCodingString(cStream.coding_type),
Format: getVideoFormatString(cStream.format),
Rate: getVideoRateString(cStream.rate),
CharCode: uint8(cStream.char_code),
Pid: uint16(cStream.pid),
Aspect: uint8(cStream.aspect),
Aspect: getAspectRatioString(cStream.aspect),
SubpathId: uint8(cStream.subpath_id),
Lang: C.GoStringN((*C.char)(unsafe.Pointer(&cStream.lang[0])), 3),
}

View File

@@ -76,19 +76,19 @@ type BlurayMetaFile struct {
}
type BlurayStreamInfo struct {
CodingType uint8
Format uint8
Rate uint8
CodingType string
Format string
Rate string
CharCode uint8
Lang string
Pid uint16
Aspect uint8
Aspect string
SubpathId uint8
}
type BlurayClipInfo struct {
PktCount uint32
StillMode uint8
StillMode string
StillTime uint16
VideoStreamCount uint8
AudioStreamCount uint8

221
tools.go
View File

@@ -1,6 +1,9 @@
package bluray
/*
#cgo pkg-config: libbluray
#include <libbluray/bluray.h>
#include <stdlib.h>
#include <stdint.h>
*/
import "C"
@@ -27,3 +30,221 @@ func getLanguageCode(langField [4]C.uint8_t) string {
}
return C.GoStringN((*C.char)(unsafe.Pointer(&langField[0])), 3)
}
// getCodingStrings 获取编码类型
// 输出: 编码类型, AUDIO/VIDEO/SUB
func getCodingStrings(codingField C.uint8_t) (string, string) {
switch codingField {
case C.BLURAY_STREAM_TYPE_VIDEO_MPEG1:
return "MPEG1", "VIDEO"
case C.BLURAY_STREAM_TYPE_VIDEO_MPEG2:
return "MPEG2", "VIDEO"
case C.BLURAY_STREAM_TYPE_AUDIO_MPEG1:
return "MPEG1", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_MPEG2:
return "MPEG2", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_LPCM:
return "LPCM", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_AC3:
return "AC3", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_DTS:
return "DTS", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_TRUHD:
return "TrueHD", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_AC3PLUS:
return "AC3+", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_DTSHD:
return "DTS-HD", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_DTSHD_MASTER:
return "DTS-HD Master", "AUDIO"
case C.BLURAY_STREAM_TYPE_VIDEO_VC1:
return "VC1", "VIDEO"
case C.BLURAY_STREAM_TYPE_VIDEO_H264:
return "H264", "VIDEO"
case C.BLURAY_STREAM_TYPE_VIDEO_HEVC:
return "HEVC", "VIDEO"
case C.BLURAY_STREAM_TYPE_SUB_PG:
return "PG", "SUB"
case C.BLURAY_STREAM_TYPE_SUB_IG:
return "IG", "SUB"
case C.BLURAY_STREAM_TYPE_SUB_TEXT:
return "TEXT", "SUB"
case C.BLURAY_STREAM_TYPE_AUDIO_AC3PLUS_SECONDARY:
return "AC3+ Secondary", "AUDIO"
case C.BLURAY_STREAM_TYPE_AUDIO_DTSHD_SECONDARY:
return "DTS-HD Secondary", "AUDIO"
default:
return "UNKNOWN", "UNKNOWN"
}
}
// getCodingString 获取编码类型
// 输出: 编码类型
func getCodingString(codingField C.uint8_t) string {
coding, _ := getCodingStrings(codingField)
return coding
}
// getVideoFormatString 获取视频格式
func getVideoFormatString(formatField C.uint8_t) string {
switch formatField {
case C.BLURAY_VIDEO_FORMAT_480I:
return "480i"
case C.BLURAY_VIDEO_FORMAT_576I:
return "576i"
case C.BLURAY_VIDEO_FORMAT_480P:
return "480p"
case C.BLURAY_VIDEO_FORMAT_1080I:
return "1080i"
case C.BLURAY_VIDEO_FORMAT_720P:
return "720p"
case C.BLURAY_VIDEO_FORMAT_1080P:
return "1080p"
case C.BLURAY_VIDEO_FORMAT_576P:
return "576p"
case C.BLURAY_VIDEO_FORMAT_2160P:
return "2160p"
default:
return "UNKNOWN"
}
}
// getAudioFormatString 获取音频格式
func getAudioFormatString(formatField C.uint8_t) string {
switch formatField {
case C.BLURAY_AUDIO_FORMAT_MONO:
return "Mono"
case C.BLURAY_AUDIO_FORMAT_STEREO:
return "Stereo"
case C.BLURAY_AUDIO_FORMAT_MULTI_CHAN:
return "Multi-channel"
case C.BLURAY_AUDIO_FORMAT_COMBO:
return "Combo" // Stereo ac3/dts,
default:
return "UNKNOWN"
}
}
// getAudioRateString 获取视频帧率
func getVideoRateString(rateField C.uint8_t) string {
switch rateField {
case C.BLURAY_VIDEO_RATE_24000_1001:
return "23.976 Hz"
case C.BLURAY_VIDEO_RATE_24:
return "24 Hz"
case C.BLURAY_VIDEO_RATE_25:
return "25 Hz"
case C.BLURAY_VIDEO_RATE_30000_1001:
return "29.97 Hz"
case C.BLURAY_VIDEO_RATE_50:
return "50 Hz"
case C.BLURAY_VIDEO_RATE_60000_1001:
return "59.94 Hz"
default:
return "UNKNOWN"
}
}
// getVideoRateFloat 获取视频帧率(浮点数)
func getVideoRateFloat(rateField C.uint8_t) float64 {
switch rateField {
case C.BLURAY_VIDEO_RATE_24000_1001:
return 23.976
case C.BLURAY_VIDEO_RATE_24:
return 24
case C.BLURAY_VIDEO_RATE_25:
return 25
case C.BLURAY_VIDEO_RATE_30000_1001:
return 29.97
case C.BLURAY_VIDEO_RATE_50:
return 50
case C.BLURAY_VIDEO_RATE_60000_1001:
return 59.94
default:
return 0
}
}
// getAudioRateString 获取音频采样率
func getAudioRateString(rateField C.uint8_t) string {
switch rateField {
case C.BLURAY_AUDIO_RATE_48:
return "48 kHz"
case C.BLURAY_AUDIO_RATE_96:
return "96 kHz"
case C.BLURAY_AUDIO_RATE_192:
return "192 kHz"
case C.BLURAY_AUDIO_RATE_192_COMBO:
return "192 kHz Combo"
case C.BLURAY_AUDIO_RATE_96_COMBO:
return "96 kHz Combo"
default:
return "UNKNOWN"
}
}
// getAudioRateFloat 获取音频采样率(浮点数)
func getAudioRateFloat(rateField C.uint8_t) int {
switch rateField {
case C.BLURAY_AUDIO_RATE_48:
return 48
case C.BLURAY_AUDIO_RATE_96:
return 96
case C.BLURAY_AUDIO_RATE_192:
return 192
case C.BLURAY_AUDIO_RATE_192_COMBO:
return 192
case C.BLURAY_AUDIO_RATE_96_COMBO:
return 96
default:
return 0
}
}
// getCharCodeString 获取字符编码
func getCharCodeString(charCode C.uint8_t) string {
switch charCode {
case C.BLURAY_TEXT_CHAR_CODE_UTF8:
return "UTF-8"
case C.BLURAY_TEXT_CHAR_CODE_UTF16BE:
return "UTF-16BE"
case C.BLURAY_TEXT_CHAR_CODE_SHIFT_JIS:
return "Shift-JIS"
case C.BLURAY_TEXT_CHAR_CODE_EUC_KR:
return "EUC-KR"
case C.BLURAY_TEXT_CHAR_CODE_GB18030_20001:
return "GB18030-2001"
case C.BLURAY_TEXT_CHAR_CODE_CN_GB:
return "CN-GB"
case C.BLURAY_TEXT_CHAR_CODE_BIG5:
return "BIG5"
default:
return "UNKNOWN"
}
}
// getAspectRatioString 获取视频宽高比
func getAspectRatioString(aspectField C.uint8_t) string {
switch aspectField {
case C.BLURAY_ASPECT_RATIO_4_3:
return "4:3"
case C.BLURAY_ASPECT_RATIO_16_9:
return "16:9"
default:
return "UNKNOWN"
}
}
// getStillModeString Clip still mode type
func getStillModeString(stillMode C.uint8_t) string {
switch stillMode {
case C.BLURAY_STILL_NONE:
return "None"
case C.BLURAY_STILL_TIME:
return "Time"
case C.BLURAY_STILL_INFINITE:
return "Infinite"
default:
return "UNKNOWN"
}
}