Skip to content

Commit

Permalink
Initial control for logging verbosity
Browse files Browse the repository at this point in the history
This doesn't do anything fancy; it just allows Haskell code to control
the log level.

Related to Issue #19
  • Loading branch information
acowley committed Mar 18, 2016
1 parent b225d53 commit 8b8c0fb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 0.11.0

* Query stream duration (Matthias Treydte)
* Initial support for verbosity control; defaults to quiet
* Can be changed with the new `setLogLevel` function

# 0.10. 0

Expand Down
3 changes: 2 additions & 1 deletion demo/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ loopFor time m =

testCamera :: IO ()
testCamera =
do initFFmpeg
do initFFmpeg -- Defaults to quiet (minimal) logging
-- setLogLevel avLogInfo -- Restore standard ffmpeg logging
(getFrame, cleanup) <- imageReader (Camera "0:0" defaultCameraConfig)
frame1 <- getFrame
case frame1 of
Expand Down
20 changes: 14 additions & 6 deletions src/Codec/FFmpeg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- | Interface to initialize FFmpeg, decode video files, encode video
-- files, and convert decoded image frames to JuicyPixels images.
module Codec.FFmpeg (-- * Initialization
initFFmpeg,
initFFmpeg, setLogLevel,
-- * Decoding
imageReader, imageReaderTime,
imageReaderT, imageReaderTimeT,
Expand All @@ -16,14 +16,22 @@ import Codec.FFmpeg.Encode
import Codec.FFmpeg.Enums
import Codec.FFmpeg.Juicy
import Codec.FFmpeg.Types
import Foreign.C.Types (CInt(..))

foreign import ccall "av_register_all" av_register_all :: IO ()
foreign import ccall "avdevice_register_all" avdevice_register_all :: IO ()

-- foreign import ccall "avcodec_register_all" avcodec_register_all :: IO ()
-- foreign import ccall "avcodec_register_all" avcodec_register_all :: IO (

-- | Initialize FFmpeg by registering all known codecs. This /must/
-- be called before using other FFmpeg functions.
initFFmpeg :: IO ()
initFFmpeg = av_register_all >> avdevice_register_all
foreign import ccall "av_log_set_level" av_log_set_level :: CInt -> IO ()

-- | Log output is sent to stderr.
setLogLevel :: LogLevel -> IO ()
setLogLevel (LogLevel l) = av_log_set_level l

-- | Initialize FFmpeg by registering all known codecs. This /must/ be
-- called before using other FFmpeg functions. The debug level is
-- initially set to @quiet@. If you would like the standard ffmpeg
-- debug level, call @setLogLevel avLogInfo@ after @initFFmpeg@.
initFFmpeg :: IO ()
initFFmpeg = av_register_all >> avdevice_register_all >> setLogLevel avLogQuiet
13 changes: 13 additions & 0 deletions src/Codec/FFmpeg/Enums.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,16 @@ newtype PacketFlag = PacketFlag CInt deriving (Eq, Bits, Storable)
#enum PacketFlag, PacketFlag \
, AV_PKT_FLAG_KEY\
, AV_PKT_FLAG_CORRUPT

newtype LogLevel = LogLevel CInt deriving (Eq, Bits, Storable)
#enum LogLevel, LogLevel \
, AV_LOG_QUIET\
, AV_LOG_PANIC\
, AV_LOG_FATAL\
, AV_LOG_ERROR\
, AV_LOG_WARNING\
, AV_LOG_INFO\
, AV_LOG_VERBOSE\
, AV_LOG_DEBUG\
, AV_LOG_TRACE\
, AV_LOG_MAX_OFFSET

0 comments on commit 8b8c0fb

Please sign in to comment.