| | |
| | | package com.anyun.h264 |
| | | |
| | | import android.os.Bundle |
| | | import android.util.Log |
| | | import timber.log.Timber |
| | | import androidx.activity.ComponentActivity |
| | | import androidx.activity.compose.setContent |
| | | import androidx.activity.enableEdgeToEdge |
| | |
| | | |
| | | private fun startH264Encoder(): Boolean { |
| | | if (h264Encoder != null) { |
| | | Log.w("MainActivity", "H264Encoder is already running") |
| | | Timber.w("H264Encoder is already running") |
| | | return false |
| | | } |
| | | |
| | |
| | | |
| | | if (h264Encoder?.initialize(cameraIdRange, null, resolution, false) == true) { |
| | | h264Encoder?.start() |
| | | Log.d("MainActivity", "H264Encoder started successfully") |
| | | Log.d("MainActivity", "Output file: ${outputFile.absolutePath}") |
| | | Timber.d("H264Encoder started successfully") |
| | | Timber.d("Output file: %s", outputFile.absolutePath) |
| | | return true |
| | | } else { |
| | | Log.e("MainActivity", "Failed to initialize H264Encoder") |
| | | Timber.e("Failed to initialize H264Encoder") |
| | | h264Encoder = null |
| | | return false |
| | | } |
| | | } catch (e: Exception) { |
| | | Log.e("MainActivity", "Failed to start H264Encoder", e) |
| | | Timber.e(e, "Failed to start H264Encoder") |
| | | h264Encoder = null |
| | | return false |
| | | } |
| | |
| | | h264Encoder?.let { encoder -> |
| | | try { |
| | | encoder.stop() |
| | | Log.d("MainActivity", "H264Encoder stopped") |
| | | Timber.d("H264Encoder stopped") |
| | | } catch (e: Exception) { |
| | | Log.e("MainActivity", "Failed to stop H264Encoder", e) |
| | | Timber.e(e, "Failed to stop H264Encoder") |
| | | } |
| | | h264Encoder = null |
| | | } |