mirror of
https://github.com/livepeer/lpms
synced 2026-04-22 15:57:25 +08:00
ffmpeg: Expose return codes.
This commit is contained in:
+2
-5
@@ -1,7 +1,6 @@
|
||||
package ffmpeg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/golang/glog"
|
||||
"unsafe"
|
||||
)
|
||||
@@ -11,8 +10,6 @@ import (
|
||||
// #include "lpms_ffmpeg.h"
|
||||
import "C"
|
||||
|
||||
var ErrFFMpegSegmenter = errors.New("FFMpegSegmenterError")
|
||||
|
||||
func RTMPToHLS(localRTMPUrl string, outM3U8 string, tmpl string, seglen_secs string) error {
|
||||
inp := C.CString(localRTMPUrl)
|
||||
outp := C.CString(outM3U8)
|
||||
@@ -24,8 +21,8 @@ func RTMPToHLS(localRTMPUrl string, outM3U8 string, tmpl string, seglen_secs str
|
||||
C.free(unsafe.Pointer(ts_tmpl))
|
||||
C.free(unsafe.Pointer(seglen))
|
||||
if 0 != ret {
|
||||
glog.Infof("RTMP2HLS Transmux Return : %d\n", ret)
|
||||
return ErrFFMpegSegmenter
|
||||
glog.Infof("RTMP2HLS Transmux Return : %v\n", Strerror(ret))
|
||||
return ErrorMap[ret]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package ffmpeg
|
||||
|
||||
// #cgo pkg-config: libavformat
|
||||
//#include "ffmpeg_errors.h"
|
||||
import "C"
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func error_map() map[int]error {
|
||||
// errs is a []byte , we really need an []int so need to convert
|
||||
errs := C.GoBytes(unsafe.Pointer(&C.ffmpeg_errors), C.sizeof_ffmpeg_errors)
|
||||
m := make(map[int]error)
|
||||
for i := 0; i < len(errs)/C.sizeof_int; i++ {
|
||||
// unsigned -> C 4-byte signed int -> golang nativeint
|
||||
// golang nativeint is usually 8 bytes on 64bit, so intermediate cast is
|
||||
// needed to preserve sign
|
||||
v := int(int32(binary.LittleEndian.Uint32(errs[i*C.sizeof_int : (i+1)*C.sizeof_int])))
|
||||
m[v] = errors.New(Strerror(v))
|
||||
}
|
||||
for i := -255; i < 0; i++ {
|
||||
v := Strerror(i)
|
||||
if "UNKNOWN_ERROR" != v {
|
||||
m[i] = errors.New(v)
|
||||
}
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
var ErrorMap = error_map()
|
||||
|
||||
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
|
||||
// Corbatto (luca@corbatto.de)
|
||||
|
||||
// Strerror returns a descriptive string of the given return code.
|
||||
//
|
||||
// C-Function: av_strerror
|
||||
func Strerror(errnum int) string {
|
||||
buf := make([]C.char, C.ffmpeg_AV_ERROR_MAX_STRING_SIZE)
|
||||
if C.av_strerror(C.int(errnum), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf))) != 0 {
|
||||
return "UNKNOWN_ERROR"
|
||||
}
|
||||
return C.GoString((*C.char)(unsafe.Pointer(&buf[0])))
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
#ifndef FFMPEG_ERRORS_H
|
||||
#define FFMPEG_ERRORS_H
|
||||
|
||||
#include <libavutil/error.h>
|
||||
#include <libavutil/avutil.h>
|
||||
|
||||
int ffmpeg_errors[] = {
|
||||
AVERROR_BSF_NOT_FOUND,
|
||||
AVERROR_BUG,
|
||||
AVERROR_BUFFER_TOO_SMALL,
|
||||
AVERROR_DECODER_NOT_FOUND,
|
||||
AVERROR_DEMUXER_NOT_FOUND,
|
||||
AVERROR_ENCODER_NOT_FOUND,
|
||||
AVERROR_EOF,
|
||||
AVERROR_EXIT,
|
||||
AVERROR_EXTERNAL,
|
||||
AVERROR_FILTER_NOT_FOUND,
|
||||
AVERROR_INVALIDDATA,
|
||||
AVERROR_MUXER_NOT_FOUND,
|
||||
AVERROR_OPTION_NOT_FOUND,
|
||||
AVERROR_PATCHWELCOME,
|
||||
AVERROR_PROTOCOL_NOT_FOUND,
|
||||
AVERROR_STREAM_NOT_FOUND,
|
||||
AVERROR_UNKNOWN,
|
||||
AVERROR_EXPERIMENTAL,
|
||||
AVERROR_INPUT_CHANGED,
|
||||
AVERROR_OUTPUT_CHANGED,
|
||||
AVERROR_HTTP_BAD_REQUEST,
|
||||
AVERROR_HTTP_UNAUTHORIZED,
|
||||
AVERROR_HTTP_FORBIDDEN,
|
||||
AVERROR_HTTP_NOT_FOUND,
|
||||
AVERROR_HTTP_OTHER_4XX,
|
||||
AVERROR_HTTP_SERVER_ERROR
|
||||
};
|
||||
|
||||
const int ffmpeg_AV_ERROR_MAX_STRING_SIZE = AV_ERROR_MAX_STRING_SIZE;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user