diff --git a/.github/actions/check_artifact_size/action.yaml b/.github/actions/check_artifact_size/action.yaml new file mode 100644 index 000000000000..f7395bea675f --- /dev/null +++ b/.github/actions/check_artifact_size/action.yaml @@ -0,0 +1,140 @@ +name: Check Artifact Size +description: Check if the increase in artifact size exceeds the threshold, and if so, apply a label to the pull request. +inputs: + workflow: + description: "Workflow to check artifact binary size for." + required: true + name: + description: "Name of the uploaded artifact, artifact is a zip file that can contain more than one binary" + required: true + path: + description: "Path to the newly created binary artifacts being checked." + required: true + thresholds: + description: "Thresholds is a JSON-formatted string that specifies the maximum permissible percentage increase in the size of each respective binary artifact." + required: true + token: + description: "Github token needed for downloading artifacts." + required: true +runs: + using: "composite" + steps: + - name: 'Download artifact from main branch' + id: download-artifact + uses: actions/github-script@v6 + with: + github-token: ${{inputs.token}} + script: | + const fs = require('fs'); + const path = require('path'); + + // Get the latest successful workflow run on the main branch. + const workflowRuns = await github.rest.actions.listWorkflowRuns({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: '${{ inputs.workflow }}.yaml', + branch: 'main', + status: 'success', + per_page: 1 + }); + + const latestRun = workflowRuns.data.workflow_runs[0].id; + + // Get the artifact uploaded on the latest successful workflow run on the main branch. + const allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: latestRun + }); + + const matchArtifacts = allArtifacts.data.artifacts.filter((artifact) => { + return artifact.name == '${{ inputs.name }}'; + }); + + if (matchArtifacts.length == 1) { + console.log(`Found the latest uploaded artifact ${{ inputs.name }} on the main branch.`); + + const download = await github.rest.actions.downloadArtifact({ + owner: context.repo.owner, + repo: context.repo.repo, + artifact_id: matchArtifacts[0].id, + archive_format: 'zip', + }); + + const downloadDir = path.join(process.env.GITHUB_WORKSPACE, 'artifact_tmp'); + fs.mkdirSync(downloadDir); + fs.writeFileSync(path.join(downloadDir, `${{ inputs.name }}.zip`), Buffer.from(download.data)); + + core.setOutput("downloadDir", downloadDir); + } else { + core.setFailed(`Expected one artifact with name ${{ inputs.name }}. Found ${matchArtifacts.length}.`); + } + + - name: 'Unzip artifact from main branch' + id: unzip-downloaded-artifact + shell: bash + run: | + unzip "${{ steps.download-artifact.outputs.downloadDir }}/${{ inputs.name }}.zip" -d "${{ steps.download-artifact.outputs.downloadDir }}" + + - name: 'Check new artifact size against main branch' + id: check-artifact-size + uses: actions/github-script@v6 + with: + script: | + const fs = require('fs'); + const path = require('path'); + + const fileSizeThresholds = JSON.parse('${{ inputs.thresholds }}'); + + for (let file in fileSizeThresholds) { + console.log(`Checking file size of ${file}.`); + + const downloadFilePath = path.join('${{ steps.download-artifact.outputs.downloadDir }}', file); + if (!fs.existsSync(downloadFilePath)) { + console.error(`File ${file} was not uploaded to the main branch.`); + continue; + } + + const filePath = path.join(process.env.GITHUB_WORKSPACE, '${{ inputs.path }}', file); + if (!fs.existsSync(filePath)) { + console.error(`File ${filePath} was not created in the current workflow run.`); + continue; + } + + const oldStats = fs.statSync(downloadFilePath); + const oldSize = oldStats.size; + const newStats = fs.statSync(filePath); + const newSize = newStats.size; + + console.log(`Latest uploaded artifact size on the main branch is ${oldSize / 1024}kB, new artifact size generated in this PR is ${newSize / 1024}kB.`); + + const deltaSize = newSize - oldSize; + const deltaThreshold = (Math.abs(deltaSize) / oldSize * 100).toFixed(4); + + if (deltaSize < 0) { + console.log(`Artifact size is decreased by ${Math.abs(deltaSize)} (${deltaThreshold}%).`); + } else { + console.log(`Artifact size is increased by ${deltaSize} (${deltaThreshold}%).`); + if (deltaThreshold > fileSizeThresholds[file]) { + const threshold = (fileSizeThresholds[file] * 100).toFixed(4); + console.error(`Artifact size increase exceeds threshold ${threshold}%.`); + core.setOutput("addLabel", true); + } + } + } + - name: 'Remove downloaded artifact' + id: remove-downloaded-artifact + shell: bash + run: rm -r "${{ steps.download-artifact.outputs.downloadDir }}" + - name: 'Add label for artifact size increase violation' + id: add-label + if: | + steps.check-artifact-size.outputs.addLabel && + github.event.pull_request.merged == true && + github.event.pull_request.merge_commit_sha != null + shell: bash + run: | + curl -s -X POST -H "Authorization: token ${{ inputs.token }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '["artifact size increase violation"]' \ + "https://api.github.com/repos/${{ github.event.repository.full_name }}/issues/${{ github.event.number }}/labels" diff --git a/.github/actions/docker_win/action.yaml b/.github/actions/docker_win/action.yaml deleted file mode 100644 index bddfa49ed73e..000000000000 --- a/.github/actions/docker_win/action.yaml +++ /dev/null @@ -1,76 +0,0 @@ -name: Docker Image Build -description: Builds Cobalt build docker images. -inputs: - service: - description: "Service name from docker compose." - required: true -runs: - using: "composite" - steps: - - name: Rename Limit - run: git config diff.renameLimit 999999 - shell: bash - - name: Get docker file changes - id: changed-files - uses: tj-actions/changed-files@2d756ea4c53f7f6b397767d8723b3a10a9f35bf2 # v44 - with: - files_ignore: third_party/** - files: | - docker-compose-windows.yml - docker/windows/** - .github/actions/docker_win/** - - name: Retrieve Docker metadata - id: meta - uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 # v4.3.0 - with: - images: ${{env.REGISTRY}}/${{github.repository}}/cobalt-${{inputs.service}} - tags: | - type=ref,event=branch - type=ref,event=tag - type=ref,event=pr - - name: Set Docker Tag - run: | - set -x - docker_tag="${{ steps.meta.outputs.tags }}" - docker_tag="${docker_tag%.1[+,-]}" - echo "DOCKER_TAG=${docker_tag}" | head -n 1 >> $GITHUB_ENV - shell: bash - # We need to set docker tag properly for pull requests. In those scenarios where no docker related files - # were changed we need to use an existing image (e.g. main). In cases where docker image is rebuilt we have - # to use tag generated by the image build. - - name: Set Docker Tag - if: ${{ (steps.changed-files.outputs.any_changed == 'false') && (github.event_name == 'pull_request') }} - env: - REPO: ${{ github.repository }} - run: echo "DOCKER_TAG=ghcr.io/${REPO}/cobalt-${{inputs.service}}:${GITHUB_BASE_REF%.1+}" >> $GITHUB_ENV - shell: bash - - name: Process Docker metadata - id: process-docker - run: | - set -x - set +e - docker manifest inspect $DOCKER_TAG > /dev/null - if [[ $? -ne 0 || ${{ steps.changed-files.outputs.any_changed }} == 'true' ]]; then - echo "need_to_build=true" >> $GITHUB_ENV - else - echo "need_to_build=false" >> $GITHUB_ENV - fi - shell: bash - - name: Build containers with Docker Compose - if: env.need_to_build == 'true' - env: - DOCKER_CPUS: 2 - SERVICE: ${{inputs.service}} - shell: bash - run: | - set -xue - docker compose -f docker-compose-windows.yml up --no-start "${SERVICE}" - - name: Tag images - if: ${{ (env.need_to_build == 'true') && ((github.event_name != 'pull_request') || (!github.event.pull_request.head.repo.fork)) }} - run: | - docker tag cobalt-${{inputs.service}} $DOCKER_TAG - shell: bash - - name: Push images - if: ${{ (env.need_to_build == 'true') && ((github.event_name != 'pull_request') || (!github.event.pull_request.head.repo.fork)) }} - run: docker push ${DOCKER_TAG} - shell: bash diff --git a/.github/config/evergreen-arm64.json b/.github/config/evergreen-arm64.json index eb7f5bbd3272..981f77a45a68 100644 --- a/.github/config/evergreen-arm64.json +++ b/.github/config/evergreen-arm64.json @@ -1,5 +1,6 @@ { - "docker_service": "build-evergreen", + "docker_service": "build-android-evergreen", + "evergreen_loader": "android-arm64", "platforms": [ "evergreen-arm64", "evergreen-arm64-sbversion-15", @@ -12,7 +13,8 @@ "platform":"evergreen-arm64", "target_platform":"evergreen-arm64", "target_cpu":"target_cpu=\\\"arm64\\\"", - "extra_gn_arguments":"use_asan=false" + "extra_gn_arguments":"use_asan=false", + "evergreen_loader_extra_gn_arguments": "target_os=\\\"android\\\" sb_is_evergreen_compatible=true" }, { "name":"sbversion-15", @@ -20,7 +22,8 @@ "target_platform":"evergreen-arm64", "target_cpu":"target_cpu=\\\"arm64\\\"", "extra_gn_arguments":"use_asan=false", - "sb_api_version":"15" + "sb_api_version":"15", + "evergreen_loader_extra_gn_arguments": "target_os=\\\"android\\\" sb_is_evergreen_compatible=true" }, { "name":"sbversion-16", @@ -28,7 +31,8 @@ "target_platform":"evergreen-arm64", "target_cpu":"target_cpu=\\\"arm64\\\"", "extra_gn_arguments":"use_asan=false", - "sb_api_version":"16" + "sb_api_version":"16", + "evergreen_loader_extra_gn_arguments": "target_os=\\\"android\\\" sb_is_evergreen_compatible=true" }, { "name":"sbversion-17", @@ -36,7 +40,8 @@ "target_platform":"evergreen-arm64", "target_cpu":"target_cpu=\\\"arm64\\\"", "extra_gn_arguments":"use_asan=false", - "sb_api_version":"17" + "sb_api_version":"17", + "evergreen_loader_extra_gn_arguments": "target_os=\\\"android\\\" sb_is_evergreen_compatible=true" } ] } diff --git a/.github/config/win32.json b/.github/config/win32.json deleted file mode 100644 index 4ffbc7cbb3e3..000000000000 --- a/.github/config/win32.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "docker_service": "build-win-win32", - "docker_runner_service": "runner-win-win32", - "runner_tag": "win32", - "platforms": [ - "win32" - ], - "on_host_test": true, - "on_host_test_shards": ["0", "1", "2", "3"], - "includes": [ - { - "name":"win32", - "platform":"win32", - "target_platform":"win-win32", - "extra_gn_arguments":"is_clang=false" - } - ] -} diff --git a/.github/config/xb1.json b/.github/config/xb1.json deleted file mode 100644 index 39d6247f5aca..000000000000 --- a/.github/config/xb1.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "docker_service": "build-xb1", - "__comment" : "TODO: Deploy a runner and change this", - "docker_runner_service": "runner-xb1", - "runner_tag": "xb1", - "platforms": [ - "xb1" - ], - "includes": [ - { - "name":"xb1", - "platform":"xb1", - "target_platform":"xb1", - "extra_gn_arguments": "is_clang=false", - "target_cpu": "target_cpu=\\\"x64\\\"", - "target_os": "target_os=\\\"winuwp\\\"" - } - ] -} diff --git a/.github/workflows/evergreen.yaml b/.github/workflows/evergreen.yaml index b9ca62af2a67..f299a90a87f4 100644 --- a/.github/workflows/evergreen.yaml +++ b/.github/workflows/evergreen.yaml @@ -31,7 +31,8 @@ jobs: platform: evergreen-x64 nightly: ${{ github.event.inputs.nightly }} run_api_leak_detector: true - keep_artifacts: libcobalt.* + keep_artifacts: install/lib/libcobalt.* + artifact_size_increase_thresholds: '{"install/lib/libcobalt.so": 0.02, "install/lib/libcobalt.lz4": 0.02}' evergreen-arm-hardfp: uses: ./.github/workflows/main.yaml permissions: @@ -41,7 +42,8 @@ jobs: platform: evergreen-arm-hardfp nightly: ${{ github.event.inputs.nightly }} run_api_leak_detector: true - keep_artifacts: libcobalt.* + keep_artifacts: install/lib/libcobalt.* + artifact_size_increase_thresholds: '{"install/lib/libcobalt.so": 0.02, "install/lib/libcobalt.lz4": 0.02}' evergreen-arm-softfp: uses: ./.github/workflows/main.yaml permissions: @@ -51,7 +53,8 @@ jobs: platform: evergreen-arm-softfp nightly: ${{ github.event.inputs.nightly }} run_api_leak_detector: true - keep_artifacts: libcobalt.* + keep_artifacts: install/lib/libcobalt.* + artifact_size_increase_thresholds: '{"install/lib/libcobalt.so": 0.02, "install/lib/libcobalt.lz4": 0.02}' evergreen-arm64: uses: ./.github/workflows/main.yaml permissions: @@ -61,4 +64,5 @@ jobs: platform: evergreen-arm64 nightly: ${{ github.event.inputs.nightly }} run_api_leak_detector: true - keep_artifacts: libcobalt.* + keep_artifacts: install/lib/libcobalt.* + artifact_size_increase_thresholds: '{"install/lib/libcobalt.so": 0.02, "install/lib/libcobalt.lz4": 0.02}' diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6f118069f965..2ff636b76ebe 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -30,10 +30,15 @@ on: type: boolean default: false keep_artifacts: - description: 'Which artifacts to keep for releases' + description: 'Which artifacts to keep for releases.' required: false type: string default: '' + artifact_size_increase_thresholds: + description: 'Threshold for artifact binary size increase.' + required: false + type: string + default: "" # Global env vars. env: @@ -257,6 +262,16 @@ jobs: uses: ./.github/actions/gn - name: Build Cobalt uses: ./.github/actions/build + - name: 'Check Artifact Size' + uses: ./.github/actions/check_artifact_size + if: ${{ inputs.artifact_size_increase_thresholds }} + continue-on-error: true # Ignore this step if check artifact size failed. + with: + workflow: ${{ github.workflow }} + name: ${{ matrix.platform }}-${{ matrix.config }} + path: out/${{ matrix.target_platform }}_${{ matrix.config }} + thresholds: ${{ inputs.artifact_size_increase_thresholds }} + token: ${{ secrets.GITHUB_TOKEN }} - name: 'Upload Artifact' uses: actions/upload-artifact@v4 if: ${{ inputs.keep_artifacts }} diff --git a/.github/workflows/main_win.yaml b/.github/workflows/main_win.yaml deleted file mode 100644 index d3ac0cfcb17e..000000000000 --- a/.github/workflows/main_win.yaml +++ /dev/null @@ -1,220 +0,0 @@ -# Reusable Cobalt CI workflow. - -name: main - -on: - workflow_call: - inputs: - platform: - description: 'Cobalt platform.' - required: true - type: string - nightly: - description: 'Nightly workflow.' - required: true - type: string - default: 'false' - modular: - description: 'Whether this is a modular build.' - required: false - type: boolean - default: false - -# Global env vars. -env: - REGISTRY: ghcr.io - IPV6_AVAILABLE: 0 - LANG: en_US.UTF-8 - IS_BUILDBOT_DOCKER: 1 - #BUILD_ID_SERVER_URL: - IS_CI: 1 - IS_DOCKER: 1 - NINJA_STATUS: '[%e sec | %f/%t %u remaining | %c/sec | j%r]' - SCCACHE: 1 - SCCACHE_GCS_BUCKET: cobalt-actions-sccache-windows - SCCACHE_GCS_OAUTH_URL: http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token - SCCACHE_GCS_RW_MODE: READ_WRITE - SCCACHE_IDLE_TIMEOUT: 0 # prevent sccache server from shutting down after long idle. - STARBOARD_TOOLCHAINS_DIR: /root/starboard-toolchains - -concurrency: - group: ${{ github.workflow }}-${{ github.event_name }}-${{ inputs.platform }} @ ${{ github.event.label.name || github.event.pull_request.number || github.sha }} @ ${{ github.event.label.name && github.event.pull_request.number || github.event.action }} - cancel-in-progress: true - -# A workflow run is made up of one or more jobs that can run sequentially or in parallel -jobs: - # Generates build matrix based on json configuration file. - initialize: - runs-on: ubuntu-latest - permissions: - pull-requests: write - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_PR_REPO_URL: ${{ github.event.pull_request.base.repo.url }} - GITHUB_EVENT_NUMBER: ${{ github.event.number }} - # All triggers except draft PRs, unless PR is labeled with runtest - if: | - github.event.action != 'labeled' || - github.event.pull_request.merged == false && - ( - github.event.action == 'labeled' && - github.event.label.name == 'runtest' || - github.event.label.name == 'on_device' - ) - timeout-minutes: 10 - steps: - - id: Checkout - uses: kaidokert/checkout@v3.5.999 # Temporary version - with: - fetch-depth: 1 - persist-credentials: false - - name: Remove runtest if exists - if: github.event_name == 'pull_request' - continue-on-error: true # Ignore this step if we cannot remove the label. - run: | - set +e - curl \ - -X DELETE \ - -H "Accept: application/vnd.github+json" \ - -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - ${GITHUB_PR_REPO_URL}/issues/${GITHUB_EVENT_NUMBER}/labels/runtest - shell: bash - - id: set-platforms - shell: bash - run: | - platforms=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -c '.platforms') - echo "platforms=${platforms}" >> $GITHUB_ENV - - id: set-includes - shell: bash - run: | - includes=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -c '.includes') - echo "includes=${includes}" >> $GITHUB_ENV - - id: set-on-device-test - shell: bash - run: | - on_device_test=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -rc '.on_device_test.enabled') - echo "on_device_test=${on_device_test}" >> $GITHUB_ENV - - id: set-on-host-test - shell: bash - run: | - on_host_test=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -rc '.on_host_test') - echo "on_host_test=${on_host_test}" >> $GITHUB_ENV - - id: set-on-host-test-shards - shell: bash - run: | - on_host_test_shards=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -c '.on_host_test_shards') - echo "on_host_test_shards=${on_host_test_shards}" >> $GITHUB_ENV - - id: set-docker-service - shell: bash - run: | - docker_service=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -rc '.docker_service') - echo "docker_service=${docker_service}" >> $GITHUB_ENV - - id: set-docker-runner-service - shell: bash - run: | - docker_runner_service=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -rc '.docker_runner_service') - echo "docker_runner_service=${docker_runner_service}" >> $GITHUB_ENV - - id: set-runner-tag - shell: bash - run: | - runner_tag=$(cat ${GITHUB_WORKSPACE}/.github/config/${{ inputs.platform }}.json | jq -rc '.runner_tag') - echo "runner_tag=${runner_tag}" >> $GITHUB_ENV - outputs: - platforms: ${{ env.platforms }} - includes: ${{ env.includes }} - on_device_test: ${{ env.on_device_test }} - on_host_test: ${{ env.on_host_test }} - on_host_test_shards: ${{ env.on_host_test_shards }} - docker_service: ${{ env.docker_service }} - docker_runner_service: ${{ env.docker_runner_service }} - runner_tag: ${{ env.runner_tag }} - # Build windows docker images. - build-docker-image: - needs: [initialize] - permissions: - packages: write - runs-on: windows-2019 - timeout-minutes: 120 - steps: - - name: Checkout files - uses: kaidokert/checkout@v3.5.999 - with: - fetch-depth: 0 - persist-credentials: false - - name: Login to Docker Registry ${{env.REGISTRY}} - uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Build docker image - id: build-docker-image - uses: ./.github/actions/docker_win - with: - service: ${{ needs.initialize.outputs.docker_service }} - - name: Build runner docker image - id: build-runner-docker-image - uses: ./.github/actions/docker_win - with: - service: ${{ needs.initialize.outputs.docker_runner_service }} - # Runs builds. - build: - needs: [initialize] - permissions: {} - runs-on: [self-hosted, "${{ needs.initialize.outputs.runner_tag }}"] - name: ${{matrix.name}}_${{matrix.config}} - strategy: - fail-fast: false - matrix: - platform: ${{ fromJson(needs.initialize.outputs.platforms) }} - include: ${{ fromJson(needs.initialize.outputs.includes) }} - config: [devel, debug, qa, gold] - timeout-minutes: 90 - steps: - - name: Checkout - uses: kaidokert/checkout@v3.5.999 - with: - # Use fetch depth of 0 to get full history for a valid build id. - fetch-depth: 0 - persist-credentials: false - - name: GN - uses: ./.github/actions/gn - - name: Build Cobalt - uses: ./.github/actions/build - - name: Upload Nightly Artifacts - if: ${{ ( inputs.nightly == 'true' || github.event_name == 'schedule' ) && matrix.config != 'debug' }} - uses: ./.github/actions/upload_nightly_artifacts - - name: Upload On Host Test Artifacts - if: ${{ matrix.config == 'devel' && needs.initialize.outputs.on_host_test == 'true' }} - uses: ./.github/actions/upload_test_artifacts - with: - type: onhost - os: windows - - # Runs on the host unit and integration tests. - on-host-test: - needs: [initialize, build] - permissions: {} - if: needs.initialize.outputs.on_host_test == 'true' - runs-on: [self-hosted, "${{ needs.initialize.outputs.runner_tag }}"] - name: ${{matrix.name}}_${{matrix.shard}}_test - strategy: - fail-fast: false - matrix: - platform: ${{ fromJson(needs.initialize.outputs.platforms) }} - shard: ${{ fromJson(needs.initialize.outputs.on_host_test_shards) }} - config: [devel] - include: ${{ fromJson(needs.initialize.outputs.includes) }} - env: - MODULAR_BUILD: ${{ inputs.modular && 1 || 0 }} - timeout-minutes: 90 - steps: - - name: Checkout - uses: kaidokert/checkout@v3.5.999 - with: - fetch-depth: 1 - persist-credentials: false - - name: Run Tests - uses: ./.github/actions/on_host_test - with: - os: windows diff --git a/.github/workflows/nightly_trigger.yaml b/.github/workflows/nightly_trigger.yaml index 22f155674572..6bcc16bd27eb 100644 --- a/.github/workflows/nightly_trigger.yaml +++ b/.github/workflows/nightly_trigger.yaml @@ -25,7 +25,6 @@ jobs: gh workflow run evergreen_23.lts.1+ --ref 23.lts.1+ -f nightly=true gh workflow run linux_23.lts.1+ --ref 23.lts.1+ -f nightly=true gh workflow run raspi-2_23.lts.1+ --ref 23.lts.1+ -f nightly=true - gh workflow run win32_23.lts.1+ --ref 23.lts.1+ -f nightly=true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} trigger_22: diff --git a/.github/workflows/pr_badges.yaml b/.github/workflows/pr_badges.yaml index 2484a99d69f4..4cba1f75af8d 100644 --- a/.github/workflows/pr_badges.yaml +++ b/.github/workflows/pr_badges.yaml @@ -46,7 +46,7 @@ jobs: const botComment = comments.find(comment => { return comment.user.type === 'Bot' && comment.body.includes('Build Status') }) - const workflows = ["lint", "android", "evergreen", "linux", "raspi-2", "stub", "win32"] + const workflows = ["lint", "android", "evergreen", "linux", "raspi-2", "stub"] var commentBody = ` ## Build Status | Workflow | Status | diff --git a/.github/workflows/win32.yaml b/.github/workflows/win32.yaml deleted file mode 100644 index 988cbb2ef464..000000000000 --- a/.github/workflows/win32.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: win32 - -on: - pull_request: - types: [opened, reopened, synchronize, labeled] - branches: - - main - - feature/* - push: - branches: - - main - - feature/* - schedule: - # GTM timezone. - - cron: '0 9 * * *' - workflow_dispatch: - inputs: - nightly: - description: 'Nightly workflow.' - required: true - type: boolean - default: false - -jobs: - win32: - uses: ./.github/workflows/main_win.yaml - permissions: - packages: write - pull-requests: write - with: - platform: win32 - nightly: ${{ github.event.inputs.nightly }} diff --git a/.github/workflows/workflow_trigger.yaml b/.github/workflows/workflow_trigger.yaml index 402b41ff3539..ed326899991c 100644 --- a/.github/workflows/workflow_trigger.yaml +++ b/.github/workflows/workflow_trigger.yaml @@ -24,7 +24,6 @@ on: - 'evergreen' - 'linux' - 'raspi' - - 'win32' nightly: description: 'Nightly workflow.' required: true diff --git a/.github/workflows/xb1.yaml b/.github/workflows/xb1.yaml deleted file mode 100644 index d819721ee67a..000000000000 --- a/.github/workflows/xb1.yaml +++ /dev/null @@ -1,32 +0,0 @@ -name: xb1 - -on: - pull_request: - types: [opened, reopened, synchronize, labeled] - branches: - - main - - feature/* - push: - branches: - - main - - feature/* - schedule: - # GTM timezone. - - cron: '0 9 * * *' - workflow_dispatch: - inputs: - nightly: - description: 'Nightly workflow.' - required: true - type: boolean - default: false - -jobs: - xb1: - uses: ./.github/workflows/main_win.yaml - permissions: - packages: write - pull-requests: write - with: - platform: xb1 - nightly: ${{ github.event.inputs.nightly }} diff --git a/base/files/file_enumerator_starboard.cc b/base/files/file_enumerator_starboard.cc index bec49f41f724..a4ebb01e4f9a 100644 --- a/base/files/file_enumerator_starboard.cc +++ b/base/files/file_enumerator_starboard.cc @@ -131,7 +131,7 @@ std::vector FileEnumerator::ReadDirectory( FilePath full_name = source.Append(filename); // TODO: Make sure this follows symlinks on relevant platforms. if (stat(full_name.value().c_str(), &info.stat_) != 0) { - DPLOG(ERROR) << "Couldn't SbFileGetInfo on " << full_name.value(); + DPLOG(ERROR) << "Couldn't stat on " << full_name.value(); memset(&info.stat_, 0, sizeof(info.stat_)); } return info; diff --git a/base/files/file_util_starboard.cc b/base/files/file_util_starboard.cc index fbd9eaa34744..bcec62a16edd 100644 --- a/base/files/file_util_starboard.cc +++ b/base/files/file_util_starboard.cc @@ -34,8 +34,8 @@ #include "base/threading/thread_restrictions.h" #include "base/time/time.h" #include "starboard/configuration_constants.h" +#include "starboard/common/file.h" #include "starboard/directory.h" -#include "starboard/file.h" #include "base/strings/strcat.h" #include "starboard/system.h" @@ -248,12 +248,12 @@ bool PathExists(const FilePath &path) { bool PathIsReadable(const FilePath &path) { internal::AssertBlockingAllowed(); - return SbFileCanOpen(path.value().c_str(), kSbFileOpenAlways | kSbFileRead); + return starboard::FileCanOpen(path.value().c_str(), O_CREAT | O_RDONLY); } bool PathIsWritable(const FilePath &path) { internal::AssertBlockingAllowed(); - return SbFileCanOpen(path.value().c_str(), kSbFileOpenAlways | kSbFileWrite); + return starboard::FileCanOpen(path.value().c_str(), O_CREAT | O_WRONLY); } bool DirectoryExists(const FilePath& path) { diff --git a/build/config/compiler/compiler.gni b/build/config/compiler/compiler.gni index d23449f7d40f..d3c27343c0a7 100644 --- a/build/config/compiler/compiler.gni +++ b/build/config/compiler/compiler.gni @@ -44,7 +44,7 @@ declare_args() { # If true, optimize for size. # Default to favoring speed over size for platforms not listed below. optimize_for_size = - !is_high_end_android && (is_android || is_ios || is_castos) + !(is_high_end_android || is_starboard) && (is_android || is_ios || is_castos) } declare_args() { diff --git a/chrome/updater/configurator.h b/chrome/updater/configurator.h index b2a432234687..9478dc709ec5 100644 --- a/chrome/updater/configurator.h +++ b/chrome/updater/configurator.h @@ -19,7 +19,6 @@ #include "cobalt/network/network_module.h" #include "components/update_client/configurator.h" #include "components/update_client/persisted_data.h" -#include "starboard/common/atomic.h" class GURL; class PrefService; diff --git a/cobalt/browser/application.cc b/cobalt/browser/application.cc index c30f30801cd9..7b852d31905d 100644 --- a/cobalt/browser/application.cc +++ b/cobalt/browser/application.cc @@ -127,10 +127,17 @@ std::string GetDevServersListenIp() { // Default to INADDR_ANY std::string listen_ip(ip_v6 ? "::" : "0.0.0.0"); +#if SB_API_VERSION < 15 + // Desktop PCs default to loopback. + if (SbSystemGetDeviceType() == kSbSystemDeviceTypeDesktopPC) { + listen_ip = ip_v6 ? "::1" : "127.0.0.1"; + } +#else if (starboard::GetSystemPropertyString(kSbSystemPropertyDeviceType) == starboard::kSystemDeviceTypeDesktopPC) { listen_ip = ip_v6 ? "::1" : "127.0.0.1"; } +#endif #if defined(ENABLE_DEBUG_COMMAND_LINE_SWITCHES) base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); diff --git a/cobalt/browser/browser_module.cc b/cobalt/browser/browser_module.cc index 3a23822791c2..99b582d3d70a 100644 --- a/cobalt/browser/browser_module.cc +++ b/cobalt/browser/browser_module.cc @@ -288,7 +288,10 @@ BrowserModule::BrowserModule(const GURL& url, splash_screen_layer_ = render_tree_combiner_.CreateLayer(kSplashScreenZIndex); // Create the debug console layer. #if defined(ENABLE_DEBUGGER) - debug_console_layer_ = render_tree_combiner_.CreateLayer(kDebugConsoleZIndex); + if (DebugConsole::IsEnabled()) { + debug_console_layer_ = + render_tree_combiner_.CreateLayer(kDebugConsoleZIndex); + } #endif int qr_code_overlay_slots = 4; @@ -367,15 +370,17 @@ BrowserModule::BrowserModule(const GURL& url, resource_provider_stub_.emplace(true /*allocate_image_data*/); #if defined(ENABLE_DEBUGGER) - debug_console_.reset(new DebugConsole( - platform_info_.get(), application_state_, - base::Bind(&BrowserModule::QueueOnDebugConsoleRenderTreeProduced, - base::Unretained(this)), - &web_settings_, network_module_, GetViewportSize(), GetResourceProvider(), - kLayoutMaxRefreshFrequencyInHz, - base::Bind(&BrowserModule::CreateDebugClient, base::Unretained(this)), - base::Bind(&BrowserModule::OnMaybeFreeze, base::Unretained(this)))); - lifecycle_observers_.AddObserver(debug_console_.get()); + if (debug_console_layer_) { + debug_console_.reset(new DebugConsole( + platform_info_.get(), application_state_, + base::Bind(&BrowserModule::QueueOnDebugConsoleRenderTreeProduced, + base::Unretained(this)), + &web_settings_, network_module_, GetViewportSize(), + GetResourceProvider(), kLayoutMaxRefreshFrequencyInHz, + base::Bind(&BrowserModule::CreateDebugClient, base::Unretained(this)), + base::Bind(&BrowserModule::OnMaybeFreeze, base::Unretained(this)))); + lifecycle_observers_.AddObserver(debug_console_.get()); + } #endif // defined(ENABLE_DEBUGGER) const renderer::Pipeline* pipeline = @@ -1095,6 +1100,7 @@ void BrowserModule::OnDisableMediaCodecs(const std::string& codecs) { void BrowserModule::QueueOnDebugConsoleRenderTreeProduced( const browser::WebModule::LayoutResults& layout_results) { +#if defined(ENABLE_DEBUGGER) TRACE_EVENT0("cobalt::browser", "BrowserModule::QueueOnDebugConsoleRenderTreeProduced()"); render_tree_submission_queue_.AddMessage( @@ -1103,14 +1109,17 @@ void BrowserModule::QueueOnDebugConsoleRenderTreeProduced( task_runner_->PostTask( FROM_HERE, base::Bind(&BrowserModule::ProcessRenderTreeSubmissionQueue, weak_this_)); +#endif } void BrowserModule::OnDebugConsoleRenderTreeProduced( const browser::WebModule::LayoutResults& layout_results) { +#if defined(ENABLE_DEBUGGER) TRACE_EVENT0("cobalt::browser", "BrowserModule::OnDebugConsoleRenderTreeProduced()"); DCHECK(task_runner_->RunsTasksInCurrentSequence()); - if (application_state_ == base::kApplicationStateConcealed) { + if (!debug_console_ || + (application_state_ == base::kApplicationStateConcealed)) { return; } @@ -1127,6 +1136,7 @@ void BrowserModule::OnDebugConsoleRenderTreeProduced( } SubmitCurrentRenderTreeToRenderer(); +#endif } void BrowserModule::OnNavigateTimedTrace(const std::string& time) { @@ -1151,7 +1161,8 @@ void BrowserModule::OnOnScreenKeyboardInputEventProduced( } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterOnScreenKeyboardInputEvent(type, event)) { + if (debug_console_ && + !debug_console_->FilterOnScreenKeyboardInputEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1188,7 +1199,7 @@ void BrowserModule::OnPointerEventProduced(base_token::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterPointerEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterPointerEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1214,7 +1225,7 @@ void BrowserModule::OnWheelEventProduced(base_token::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterWheelEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterWheelEvent(type, event)) { return; } #endif // defined(ENABLE_DEBUGGER) @@ -1348,7 +1359,7 @@ bool BrowserModule::FilterKeyEvent(base_token::Token type, } #if defined(ENABLE_DEBUGGER) - if (!debug_console_->FilterKeyEvent(type, event)) { + if (debug_console_ && !debug_console_->FilterKeyEvent(type, event)) { return false; } #endif // defined(ENABLE_DEBUGGER) @@ -1359,8 +1370,9 @@ bool BrowserModule::FilterKeyEvent(base_token::Token type, bool BrowserModule::FilterKeyEventForHotkeys( base_token::Token type, const dom::KeyboardEventInit& event) { #if defined(ENABLE_DEBUGGER) - if (event.key_code() == dom::keycode::kF1 || - (event.ctrl_key() && event.key_code() == dom::keycode::kO)) { + if (debug_console_ && + (event.key_code() == dom::keycode::kF1 || + (event.ctrl_key() && event.key_code() == dom::keycode::kO))) { if (type == base::Tokens::keydown()) { // F1 or Ctrl+O cycles the debug console display. debug_console_->CycleMode(); @@ -1754,7 +1766,9 @@ void BrowserModule::ResetResources() { main_web_module_layer_->Reset(); splash_screen_layer_->Reset(); #if defined(ENABLE_DEBUGGER) - debug_console_layer_->Reset(); + if (debug_console_layer_) { + debug_console_layer_->Reset(); + } #endif // defined(ENABLE_DEBUGGER) if (qr_overlay_info_layer_) { qr_overlay_info_layer_->Reset(); diff --git a/cobalt/browser/debug_console.cc b/cobalt/browser/debug_console.cc index 42c73aecc1aa..4c6b50c1c4dc 100644 --- a/cobalt/browser/debug_console.cc +++ b/cobalt/browser/debug_console.cc @@ -157,6 +157,18 @@ DebugConsole::DebugConsole( DebugConsole::~DebugConsole() {} +// static +bool DebugConsole::IsEnabled() { +#if defined(ENABLE_DEBUGGER) + // The debug console is not enabled when it's turned off from the + // command-line. + return GetDebugConsoleModeFromCommandLine() != + debug::console::kDebugConsoleModeOff; +#else + return false; +#endif +} + bool DebugConsole::ShouldInjectInputEvents() { switch (GetMode()) { case debug::console::kDebugConsoleModeOff: diff --git a/cobalt/browser/debug_console.h b/cobalt/browser/debug_console.h index 075dbfe12715..265d46d7d2f1 100644 --- a/cobalt/browser/debug_console.h +++ b/cobalt/browser/debug_console.h @@ -88,6 +88,9 @@ class DebugConsole : public LifecycleObserver { // Cycles through each different possible debug console visibility mode. void CycleMode(); + // Returns true if the debug console is enabled. + static bool IsEnabled(); + // Returns true iff the console is in a mode that is visible. bool IsVisible() { return (GetMode() != debug::console::kDebugConsoleModeOff); diff --git a/cobalt/browser/user_agent_platform_info.cc b/cobalt/browser/user_agent_platform_info.cc index a6563bf9b43d..5c0d65895531 100644 --- a/cobalt/browser/user_agent_platform_info.cc +++ b/cobalt/browser/user_agent_platform_info.cc @@ -110,6 +110,47 @@ void GetUserAgentInputMap( namespace { +#if SB_API_VERSION < 15 + +struct DeviceTypeName { + SbSystemDeviceType device_type; + char device_type_string[10]; +}; + +const DeviceTypeName kDeviceTypeStrings[] = { + {kSbSystemDeviceTypeBlueRayDiskPlayer, "BDP"}, + {kSbSystemDeviceTypeGameConsole, "GAME"}, + {kSbSystemDeviceTypeOverTheTopBox, "OTT"}, + {kSbSystemDeviceTypeSetTopBox, "STB"}, + {kSbSystemDeviceTypeTV, "TV"}, + {kSbSystemDeviceTypeAndroidTV, "ATV"}, + {kSbSystemDeviceTypeDesktopPC, "DESKTOP"}, + {kSbSystemDeviceTypeVideoProjector, "PROJECTOR"}, + {kSbSystemDeviceTypeUnknown, "UNKNOWN"}}; + +std::string CreateDeviceTypeString(SbSystemDeviceType device_type) { + for (auto& map : kDeviceTypeStrings) { + if (map.device_type == device_type) { + return std::string(map.device_type_string); + } + } + NOTREACHED(); + return "UNKNOWN"; +} + +#if !defined(COBALT_BUILD_TYPE_GOLD) +SbSystemDeviceType GetDeviceType(std::string device_type_string) { + for (auto& map : kDeviceTypeStrings) { + if (!SbStringCompareNoCase(map.device_type_string, + device_type_string.c_str())) { + return map.device_type; + } + } + return kSbSystemDeviceTypeUnknown; +} +#endif +#endif // SB_API_VERSION < 15 + static bool isAsciiAlphaDigit(int c) { return base::IsAsciiAlpha(c) || base::IsAsciiDigit(c); } @@ -279,10 +320,15 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) { info.set_aux_field(value); } +#if SB_API_VERSION >= 15 result = SbSystemGetProperty(kSbSystemPropertyDeviceType, value, kSystemPropertyMaxLength); SB_DCHECK(result); info.set_device_type(value); +#else + // Fill platform info if it is a hardware TV device. + info.set_device_type(SbSystemGetDeviceType()); +#endif // Chipset model number result = SbSystemGetProperty(kSbSystemPropertyChipsetModelNumber, value, @@ -349,7 +395,11 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) { info.set_original_design_manufacturer(input.second); LOG(INFO) << "Set original design manufacturer to " << input.second; } else if (!input.first.compare("device_type")) { +#if SB_API_VERSION < 15 + info.set_device_type(GetDeviceType(input.second)); +#else info.set_device_type(input.second); +#endif LOG(INFO) << "Set device type to " << input.second; } else if (!input.first.compare("chipset_model_number")) { info.set_chipset_model_number(input.second); @@ -435,6 +485,12 @@ void UserAgentPlatformInfo::set_original_design_manufacturer( } } +#if SB_API_VERSION < 15 +void UserAgentPlatformInfo::set_device_type(SbSystemDeviceType device_type) { + device_type_ = device_type; + device_type_string_ = CreateDeviceTypeString(device_type_); +} +#endif void UserAgentPlatformInfo::set_device_type(const std::string& device_type) { device_type_string_ = device_type; } diff --git a/cobalt/browser/user_agent_platform_info.h b/cobalt/browser/user_agent_platform_info.h index 78a1cc84306a..f9267345dff2 100644 --- a/cobalt/browser/user_agent_platform_info.h +++ b/cobalt/browser/user_agent_platform_info.h @@ -43,6 +43,11 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo { base::Optional original_design_manufacturer() const override { return original_design_manufacturer_; } + +#if SB_API_VERSION < 15 + SbSystemDeviceType device_type() const override { return device_type_; } +#endif + const std::string& device_type_string() const override { return device_type_string_; } @@ -96,6 +101,9 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo { void set_os_name_and_version(const std::string& os_name_and_version); void set_original_design_manufacturer( base::Optional original_design_manufacturer); +#if SB_API_VERSION < 15 + void set_device_type(SbSystemDeviceType device_type); +#endif void set_device_type(const std::string& device_type); void set_chipset_model_number( base::Optional chipset_model_number); @@ -124,6 +132,9 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo { std::string starboard_version_; std::string os_name_and_version_; base::Optional original_design_manufacturer_; +#if SB_API_VERSION < 15 + SbSystemDeviceType device_type_ = kSbSystemDeviceTypeUnknown; +#endif std::string device_type_string_; base::Optional chipset_model_number_; base::Optional model_year_; diff --git a/cobalt/dom/html_media_element.cc b/cobalt/dom/html_media_element.cc index e811bfcd6440..6aa4a1713616 100644 --- a/cobalt/dom/html_media_element.cc +++ b/cobalt/dom/html_media_element.cc @@ -706,12 +706,16 @@ void HTMLMediaElement::ScheduleEvent(const scoped_refptr& event) { } std::string HTMLMediaElement::h5vcc_audio_connectors() const { +#if SB_API_VERSION >= 15 if (!player_) { return ""; } std::vector configs = player_->GetAudioConnectors(); return base::JoinString(configs, ";"); +#else // SB_API_VERSION >= 15 + return ""; +#endif // SB_API_VERSION >= 15 } void HTMLMediaElement::CreateMediaPlayer() { diff --git a/cobalt/dom/keyboard_event.cc b/cobalt/dom/keyboard_event.cc index 37cda49e9a7d..ad854118b1db 100644 --- a/cobalt/dom/keyboard_event.cc +++ b/cobalt/dom/keyboard_event.cc @@ -337,8 +337,10 @@ std::string KeyboardEvent::NonPrintableKey(int32_t key_code) const { return "MediaStop"; case keycode::kMediaPlayPause: return "MediaPlayPause"; +#if SB_API_VERSION >= 15 case keycode::kMediaRecord: return "MediaRecord"; +#endif case keycode::kMediaLaunchMail: return "LaunchMail"; case keycode::kMediaLaunchMediaSelect: diff --git a/cobalt/dom/keyboard_event_test.cc b/cobalt/dom/keyboard_event_test.cc index c189ccc1ddc4..0f9843e72881 100644 --- a/cobalt/dom/keyboard_event_test.cc +++ b/cobalt/dom/keyboard_event_test.cc @@ -135,12 +135,14 @@ TEST_F(KeyboardEventTest, CanGetKeyIdentifierAndKeyAndCode) { EXPECT_EQ(keyboard_event_space->key(), " "); EXPECT_EQ(keyboard_event_space->code(), "Space"); +#if SB_API_VERSION >= 15 init.set_key_code(keycode::kMediaRecord); scoped_refptr keyboard_event_record = new KeyboardEvent("keydown", init); EXPECT_EQ(keyboard_event_record->key_identifier(), "MediaRecord"); EXPECT_EQ(keyboard_event_record->key(), "MediaRecord"); EXPECT_EQ(keyboard_event_record->code(), "MediaRecord"); +#endif } TEST_F(KeyboardEventTest, CanGetAltKey) { diff --git a/cobalt/dom/keycode.h b/cobalt/dom/keycode.h index 5623e52f745b..afda18fa6df4 100644 --- a/cobalt/dom/keycode.h +++ b/cobalt/dom/keycode.h @@ -200,7 +200,9 @@ enum { // Not present in Windows virtual key codes, but would be used by the client. kMediaRewind = 0xE3, kMediaFastForward = 0xE4, +#if SB_API_VERSION >= 15 kMediaRecord = 0x1A0, +#endif }; } // namespace keycode diff --git a/cobalt/extension/configuration.h b/cobalt/extension/configuration.h new file mode 100644 index 000000000000..36f5ae456cf6 --- /dev/null +++ b/cobalt/extension/configuration.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_CONFIGURATION_H_ +#define COBALT_EXTENSION_CONFIGURATION_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/configuration.h" +#else +#error "Extensions have moved, please see CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_CONFIGURATION_H_ diff --git a/cobalt/extension/crash_handler.h b/cobalt/extension/crash_handler.h new file mode 100644 index 000000000000..628c27eea1dd --- /dev/null +++ b/cobalt/extension/crash_handler.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_CRASH_HANDLER_H_ +#define COBALT_EXTENSION_CRASH_HANDLER_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/crash_handler.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_CRASH_HANDLER_H_ diff --git a/cobalt/extension/demuxer.h b/cobalt/extension/demuxer.h new file mode 100644 index 000000000000..96e210b6fe15 --- /dev/null +++ b/cobalt/extension/demuxer.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_DEMUXER_H_ +#define COBALT_EXTENSION_DEMUXER_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/demuxer.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_DEMUXER_H_ diff --git a/cobalt/extension/font.h b/cobalt/extension/font.h new file mode 100644 index 000000000000..6eaac679eaac --- /dev/null +++ b/cobalt/extension/font.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_FONT_H_ +#define COBALT_EXTENSION_FONT_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/font.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_FONT_H_ diff --git a/cobalt/extension/free_space.h b/cobalt/extension/free_space.h new file mode 100644 index 000000000000..856cf17cab39 --- /dev/null +++ b/cobalt/extension/free_space.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_FREE_SPACE_H_ +#define COBALT_EXTENSION_FREE_SPACE_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/free_space.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_FREE_SPACE_H_ diff --git a/cobalt/extension/graphics.h b/cobalt/extension/graphics.h new file mode 100644 index 000000000000..e7943c942822 --- /dev/null +++ b/cobalt/extension/graphics.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_GRAPHICS_H_ +#define COBALT_EXTENSION_GRAPHICS_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/graphics.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_GRAPHICS_H_ diff --git a/cobalt/extension/installation_manager.h b/cobalt/extension/installation_manager.h new file mode 100644 index 000000000000..97a07579efe5 --- /dev/null +++ b/cobalt/extension/installation_manager.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_INSTALLATION_MANAGER_H_ +#define COBALT_EXTENSION_INSTALLATION_MANAGER_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/installation_manager.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_INSTALLATION_MANAGER_H_ diff --git a/cobalt/extension/javascript_cache.h b/cobalt/extension/javascript_cache.h new file mode 100644 index 000000000000..ef58a742b751 --- /dev/null +++ b/cobalt/extension/javascript_cache.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_JAVASCRIPT_CACHE_H_ +#define COBALT_EXTENSION_JAVASCRIPT_CACHE_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/javascript_cache.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_JAVASCRIPT_CACHE_H_ diff --git a/cobalt/extension/media_session.h b/cobalt/extension/media_session.h new file mode 100644 index 000000000000..1aebd300b75d --- /dev/null +++ b/cobalt/extension/media_session.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_MEDIA_SESSION_H_ +#define COBALT_EXTENSION_MEDIA_SESSION_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/media_session.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_MEDIA_SESSION_H_ diff --git a/cobalt/extension/memory_mapped_file.h b/cobalt/extension/memory_mapped_file.h new file mode 100644 index 000000000000..c5ac54c3c517 --- /dev/null +++ b/cobalt/extension/memory_mapped_file.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_MEMORY_MAPPED_FILE_H_ +#define COBALT_EXTENSION_MEMORY_MAPPED_FILE_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/memory_mapped_file.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_MEMORY_MAPPED_FILE_H_ diff --git a/cobalt/extension/platform_service.h b/cobalt/extension/platform_service.h new file mode 100644 index 000000000000..fca88ef9aef9 --- /dev/null +++ b/cobalt/extension/platform_service.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_PLATFORM_SERVICE_H_ +#define COBALT_EXTENSION_PLATFORM_SERVICE_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/platform_service.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_PLATFORM_SERVICE_H_ diff --git a/cobalt/extension/updater_notification.h b/cobalt/extension/updater_notification.h new file mode 100644 index 000000000000..e56e77dae826 --- /dev/null +++ b/cobalt/extension/updater_notification.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_UPDATER_NOTIFICATION_H_ +#define COBALT_EXTENSION_UPDATER_NOTIFICATION_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/updater_notification.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_UPDATER_NOTIFICATION_H_ diff --git a/cobalt/extension/url_fetcher_observer.h b/cobalt/extension/url_fetcher_observer.h new file mode 100644 index 000000000000..65619d3bbc31 --- /dev/null +++ b/cobalt/extension/url_fetcher_observer.h @@ -0,0 +1,24 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef COBALT_EXTENSION_URL_FETCHER_OBSERVER_H_ +#define COBALT_EXTENSION_URL_FETCHER_OBSERVER_H_ + +#if SB_API_VERSION <= 14 +#include "starboard/extension/url_fetcher_observer.h" +#else +#error "Extensions have moved, please see Starboard CHANGELOG for details." +#endif + +#endif // COBALT_EXTENSION_URL_FETCHER_OBSERVER_H_ diff --git a/cobalt/h5vcc/h5vcc_settings.cc b/cobalt/h5vcc/h5vcc_settings.cc index b42ffc6e13b3..0cb5ca7ef878 100644 --- a/cobalt/h5vcc/h5vcc_settings.cc +++ b/cobalt/h5vcc/h5vcc_settings.cc @@ -57,6 +57,7 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const { const char kMediaCodecBlockList[] = "MediaCodecBlockList"; const char kNavigatorUAData[] = "NavigatorUAData"; const char kQUIC[] = "QUIC"; + const char kHTTP2[] = "HTTP2"; const char kHTTP3[] = "HTTP3"; const char kSkiaRasterizer[] = "SkiaRasterizer"; @@ -70,11 +71,6 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const { return true; } - if (set_web_setting_func_ && value.IsType() && - set_web_setting_func_.Run(name, value.AsType())) { - return true; - } - if (name.rfind(kMediaPrefix, 0) == 0 && value.IsType()) { return media_module_ ? media_module_->SetConfiguration( @@ -100,6 +96,17 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const { } } + if (name.compare(kHTTP2) == 0 && value.IsType()) { + if (!persistent_settings_ || !network_module_) { + return false; + } else { + persistent_settings_->Set(network::kHttp2EnabledPersistentSettingsKey, + base::Value(value.AsType() != 0)); + network_module_->SetEnableHttp2FromPersistentSettings(); + return true; + } + } + if (name.compare(kHTTP3) == 0 && value.IsType()) { if (!persistent_settings_ || !network_module_) { return false; @@ -153,6 +160,11 @@ bool H5vccSettings::Set(const std::string& name, SetValueType value) const { return true; } #endif + if (set_web_setting_func_ && value.IsType() && + set_web_setting_func_.Run(name, value.AsType())) { + return true; + } + return false; } diff --git a/cobalt/media/base/sbplayer_bridge.cc b/cobalt/media/base/sbplayer_bridge.cc index b806e21541b1..3d0305fb7fff 100644 --- a/cobalt/media/base/sbplayer_bridge.cc +++ b/cobalt/media/base/sbplayer_bridge.cc @@ -73,7 +73,11 @@ void SetStreamInfo(const SbMediaAudioStreamInfo& stream_info, SbMediaAudioSampleInfo* sample_info) { DCHECK(sample_info); +#if SB_API_VERSION >= 15 sample_info->stream_info = stream_info; +#else // SB_API_VERSION >= 15 + *sample_info = stream_info; +#endif // SB_API_VERSION >= 15} } void SetStreamInfo( @@ -93,7 +97,11 @@ void SetStreamInfo(const SbMediaVideoStreamInfo& stream_info, SbMediaVideoSampleInfo* sample_info) { DCHECK(sample_info); +#if SB_API_VERSION >= 15 sample_info->stream_info = stream_info; +#else // SB_API_VERSION >= 15 + *sample_info = stream_info; +#endif // SB_API_VERSION >= 15} } void SetDiscardPadding( @@ -112,10 +120,12 @@ void SetDiscardPadding( SbMediaAudioSampleInfo* sample_info) { DCHECK(sample_info); +#if SB_API_VERSION >= 15 sample_info->discarded_duration_from_front = discard_padding.first.InMicroseconds(); sample_info->discarded_duration_from_back = discard_padding.second.InMicroseconds(); +#endif // SB_API_VERSION >= 15} } } // namespace @@ -457,6 +467,7 @@ void SbPlayerBridge::GetInfo(uint32* video_frames_decoded, GetInfo_Locked(video_frames_decoded, video_frames_dropped, media_time); } +#if SB_API_VERSION >= 15 std::vector SbPlayerBridge::GetAudioConfigurations() { base::AutoLock auto_lock(lock_); @@ -485,6 +496,7 @@ SbPlayerBridge::GetAudioConfigurations() { return configurations; } +#endif // SB_API_VERSION >= 15 #if SB_HAS(PLAYER_WITH_URL) void SbPlayerBridge::GetUrlPlayerBufferedTimeRanges( @@ -526,7 +538,11 @@ void SbPlayerBridge::GetVideoResolution(int* frame_width, int* frame_height) { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo out_player_info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 out_player_info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &out_player_info); video_stream_info_.frame_width = out_player_info.frame_width; @@ -545,7 +561,11 @@ TimeDelta SbPlayerBridge::GetDuration() { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); if (info.duration == SB_PLAYER_NO_DURATION) { // URL-based player may not have loaded asset yet, so map no duration to 0. @@ -563,7 +583,11 @@ TimeDelta SbPlayerBridge::GetStartDate() { DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); return TimeDelta::FromMicroseconds(info.start_date); } @@ -736,13 +760,22 @@ void SbPlayerBridge::CreatePlayer() { SbPlayerCreationParam creation_param = {}; creation_param.drm_system = drm_system_; +#if SB_API_VERSION >= 15 creation_param.audio_stream_info = audio_stream_info_; creation_param.video_stream_info = video_stream_info_; +#else // SB_API_VERSION >= 15 + creation_param.audio_sample_info = audio_stream_info_; + creation_param.video_sample_info = video_stream_info_; +#endif // SB_API_VERSION >= 15 // TODO: This is temporary for supporting background media playback. // Need to be removed with media refactor. if (!is_visible) { +#if SB_API_VERSION >= 15 creation_param.video_stream_info.codec = kSbMediaVideoCodecNone; +#else // SB_API_VERSION >= 15 + creation_param.video_sample_info.codec = kSbMediaVideoCodecNone; +#endif // SB_API_VERSION >= 15 } creation_param.output_mode = output_mode_; DCHECK_EQ(sbplayer_interface_->GetPreferredOutputMode(&creation_param), @@ -977,7 +1010,11 @@ void SbPlayerBridge::GetInfo_Locked(uint32* video_frames_decoded, DCHECK(SbPlayerIsValid(player_)); +#if SB_API_VERSION >= 15 SbPlayerInfo info; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; +#endif // SB_API_VERSION >= 15 sbplayer_interface_->GetInfo(player_, &info); if (media_time) { @@ -1223,8 +1260,13 @@ SbPlayerOutputMode SbPlayerBridge::ComputeSbPlayerOutputMode( SbPlayerCreationParam creation_param = {}; creation_param.drm_system = drm_system_; +#if SB_API_VERSION >= 15 creation_param.audio_stream_info = audio_stream_info_; creation_param.video_stream_info = video_stream_info_; +#else // SB_API_VERSION >= 15 + creation_param.audio_sample_info = audio_stream_info_; + creation_param.video_sample_info = video_stream_info_; +#endif // SB_API_VERSION >= 15 if (default_output_mode != kSbPlayerOutputModeDecodeToTexture && video_stream_info_.codec != kSbMediaVideoCodecNone) { diff --git a/cobalt/media/base/sbplayer_bridge.h b/cobalt/media/base/sbplayer_bridge.h index 98ab7fdf4ba8..f6cc6879c12b 100644 --- a/cobalt/media/base/sbplayer_bridge.h +++ b/cobalt/media/base/sbplayer_bridge.h @@ -118,7 +118,9 @@ class SbPlayerBridge { void SetPlaybackRate(double playback_rate); void GetInfo(uint32* video_frames_decoded, uint32* video_frames_dropped, base::TimeDelta* media_time); +#if SB_API_VERSION >= 15 std::vector GetAudioConfigurations(); +#endif // SB_API_VERSION >= 15 #if SB_HAS(PLAYER_WITH_URL) void GetUrlPlayerBufferedTimeRanges(base::TimeDelta* buffer_start_time, diff --git a/cobalt/media/base/sbplayer_interface.cc b/cobalt/media/base/sbplayer_interface.cc index 3f6059160ba8..ec7b76d1acc1 100644 --- a/cobalt/media/base/sbplayer_interface.cc +++ b/cobalt/media/base/sbplayer_interface.cc @@ -91,7 +91,11 @@ void DefaultSbPlayerInterface::Destroy(SbPlayer player) { void DefaultSbPlayerInterface::Seek(SbPlayer player, base::TimeDelta seek_to_timestamp, int ticket) { +#if SB_API_VERSION >= 15 SbPlayerSeek(player, seek_to_timestamp.InMicroseconds(), ticket); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, seek_to_timestamp.InMicroseconds(), ticket); +#endif // SB_API_VERSION >= 15 } bool DefaultSbPlayerInterface::IsEnhancedAudioExtensionEnabled() const { @@ -102,8 +106,13 @@ void DefaultSbPlayerInterface::WriteSamples( SbPlayer player, SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos) { DCHECK(!IsEnhancedAudioExtensionEnabled()); +#if SB_API_VERSION >= 15 SbPlayerWriteSamples(player, sample_type, sample_infos, number_of_sample_infos); +#else // SB_API_VERSION >= 15 + SbPlayerWriteSample2(player, sample_type, sample_infos, + number_of_sample_infos); +#endif // SB_API_VERSION >= 15 } void DefaultSbPlayerInterface::WriteSamples( @@ -140,8 +149,13 @@ void DefaultSbPlayerInterface::SetVolume(SbPlayer player, double volume) { } void DefaultSbPlayerInterface::GetInfo(SbPlayer player, +#if SB_API_VERSION >= 15 SbPlayerInfo* out_player_info) { SbPlayerGetInfo(player, out_player_info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2* out_player_info2) { + SbPlayerGetInfo2(player, out_player_info2); +#endif // SB_API_VERSION >= 15 } SbDecodeTarget DefaultSbPlayerInterface::GetCurrentFrame(SbPlayer player) { @@ -180,11 +194,15 @@ void DefaultSbPlayerInterface::GetUrlPlayerExtraInfo( } #endif // SB_HAS(PLAYER_WITH_URL) +#if SB_API_VERSION >= 15 + bool DefaultSbPlayerInterface::GetAudioConfiguration( SbPlayer player, int index, SbMediaAudioConfiguration* out_audio_configuration) { return SbPlayerGetAudioConfiguration(player, index, out_audio_configuration); } +#endif // SB_API_VERSION >= 15 + } // namespace media } // namespace cobalt diff --git a/cobalt/media/base/sbplayer_interface.h b/cobalt/media/base/sbplayer_interface.h index 54b3de18d50c..4aba0395eaa0 100644 --- a/cobalt/media/base/sbplayer_interface.h +++ b/cobalt/media/base/sbplayer_interface.h @@ -62,7 +62,11 @@ class SbPlayerInterface { virtual bool SetPlaybackRate(SbPlayer player, double playback_rate) = 0; virtual void SetVolume(SbPlayer player, double volume) = 0; +#if SB_API_VERSION >= 15 virtual void GetInfo(SbPlayer player, SbPlayerInfo* out_player_info) = 0; +#else // SB_API_VERSION >= 15 + virtual void GetInfo(SbPlayer player, SbPlayerInfo2* out_player_info2) = 0; +#endif // SB_API_VERSION >= 15 virtual SbDecodeTarget GetCurrentFrame(SbPlayer player) = 0; #if SB_HAS(PLAYER_WITH_URL) @@ -80,9 +84,11 @@ class SbPlayerInterface { SbPlayer player, SbUrlPlayerExtraInfo* out_url_player_info) = 0; #endif // SB_HAS(PLAYER_WITH_URL) +#if SB_API_VERSION >= 15 virtual bool GetAudioConfiguration( SbPlayer player, int index, SbMediaAudioConfiguration* out_audio_configuration) = 0; +#endif // SB_API_VERSION >= 15 // disabled by default, but can be enabled via h5vcc setting. void EnableCValStats(bool should_enable) { @@ -125,7 +131,11 @@ class DefaultSbPlayerInterface final : public SbPlayerInterface { int height) override; bool SetPlaybackRate(SbPlayer player, double playback_rate) override; void SetVolume(SbPlayer player, double volume) override; +#if SB_API_VERSION >= 15 void GetInfo(SbPlayer player, SbPlayerInfo* out_player_info) override; +#else // SB_API_VERSION >= 15 + void GetInfo(SbPlayer player, SbPlayerInfo2* out_player_info2) override; +#endif // SB_API_VERSION >= 15 SbDecodeTarget GetCurrentFrame(SbPlayer player) override; #if SB_HAS(PLAYER_WITH_URL) @@ -141,9 +151,11 @@ class DefaultSbPlayerInterface final : public SbPlayerInterface { SbPlayer player, SbUrlPlayerExtraInfo* out_url_player_info) override; #endif // SB_HAS(PLAYER_WITH_URL) +#if SB_API_VERSION >= 15 bool GetAudioConfiguration( SbPlayer player, int index, SbMediaAudioConfiguration* out_audio_configuration) override; +#endif // SB_API_VERSION >= 15 private: void (*enhanced_audio_player_write_samples_)( diff --git a/cobalt/media/base/sbplayer_pipeline.cc b/cobalt/media/base/sbplayer_pipeline.cc index 7b69fd52fde3..12efde9c12e1 100644 --- a/cobalt/media/base/sbplayer_pipeline.cc +++ b/cobalt/media/base/sbplayer_pipeline.cc @@ -59,6 +59,7 @@ const int kPrerollGuardAudioBuffer = 1; unsigned int g_pipeline_identifier_counter = 0; +#if SB_API_VERSION >= 15 bool HasRemoteAudioOutputs( const std::vector& configurations) { for (auto&& configuration : configurations) { @@ -87,6 +88,7 @@ bool HasRemoteAudioOutputs( return false; } +#endif // SB_API_VERSION >= 15 // The function adjusts audio write duration proportionally to the playback // rate, when the playback rate is greater than 1.0. @@ -133,9 +135,11 @@ SbPlayerPipeline::SbPlayerPipeline( const GetDecodeTargetGraphicsContextProviderFunc& get_decode_target_graphics_context_provider_func, bool allow_resume_after_suspend, int max_audio_samples_per_write, - bool force_punch_out_by_default, TimeDelta audio_write_duration_local, - TimeDelta audio_write_duration_remote, MediaLog* media_log, - MediaMetricsProvider* media_metrics_provider, + bool force_punch_out_by_default, +#if SB_API_VERSION >= 15 + TimeDelta audio_write_duration_local, TimeDelta audio_write_duration_remote, +#endif // SB_API_VERSION >= 15 + MediaLog* media_log, MediaMetricsProvider* media_metrics_provider, DecodeTargetProvider* decode_target_provider) : pipeline_identifier_( base::StringPrintf("%X", g_pipeline_identifier_counter++)), @@ -177,8 +181,10 @@ SbPlayerPipeline::SbPlayerPipeline( kSbPlayerStateInitialized, "The underlying SbPlayer state of the media pipeline."), decode_target_provider_(decode_target_provider), +#if SB_API_VERSION >= 15 audio_write_duration_local_(audio_write_duration_local), audio_write_duration_remote_(audio_write_duration_remote), +#endif // SB_API_VERSION >= 15 media_metrics_provider_(media_metrics_provider), last_media_time_(base::StringPrintf("Media.Pipeline.%s.LastMediaTime", pipeline_identifier_.c_str()), @@ -196,7 +202,6 @@ SbPlayerPipeline::SbPlayerPipeline( SbPlayerPipeline::~SbPlayerPipeline() { DCHECK(!player_bridge_); } - void SbPlayerPipeline::Suspend() { DCHECK(!task_runner_->RunsTasksInCurrentSequence()); @@ -580,6 +585,7 @@ void SbPlayerPipeline::GetNaturalVideoSize(gfx::Size* out_size) const { } std::vector SbPlayerPipeline::GetAudioConnectors() const { +#if SB_API_VERSION >= 15 base::AutoLock auto_lock(lock_); if (!player_bridge_) { return std::vector(); @@ -600,6 +606,9 @@ std::vector SbPlayerPipeline::GetAudioConnectors() const { } return connectors; +#else // SB_API_VERSION >= 15 + return std::vector(); +#endif // SB_API_VERSION >= 15 } bool SbPlayerPipeline::DidLoadingProgress() const { @@ -859,6 +868,7 @@ void SbPlayerPipeline::CreatePlayer(SbDrmSystem drm_system) { default_output_mode_, decode_target_provider_, max_video_capabilities_, max_video_input_size_, pipeline_identifier_)); if (player_bridge_->IsValid()) { +#if SB_API_VERSION >= 15 // TODO(b/267678497): When `player_bridge_->GetAudioConfigurations()` // returns no audio configurations, update the write durations again // before the SbPlayer reaches `kSbPlayerStatePresenting`. @@ -868,6 +878,7 @@ void SbPlayerPipeline::CreatePlayer(SbDrmSystem drm_system) { : audio_write_duration_local_; LOG(INFO) << "SbPlayerBridge created, with audio write duration at " << audio_write_duration_for_preroll_; +#endif // SB_API_VERSION >= 15 SetPlaybackRateTask(playback_rate_); SetVolumeTask(volume_); @@ -1301,12 +1312,14 @@ void SbPlayerPipeline::OnPlayerStatus(SbPlayerState state) { } #endif // SB_HAS(PLAYER_WITH_URL) +#if SB_API_VERSION >= 15 audio_write_duration_for_preroll_ = audio_write_duration_ = HasRemoteAudioOutputs(player_bridge_->GetAudioConfigurations()) ? audio_write_duration_remote_ : audio_write_duration_local_; LOG(INFO) << "SbPlayerBridge reaches kSbPlayerStatePresenting, with audio" << " write duration at " << audio_write_duration_; +#endif // SB_API_VERSION >= 15 break; } case kSbPlayerStateEndOfStream: diff --git a/cobalt/media/base/sbplayer_pipeline.h b/cobalt/media/base/sbplayer_pipeline.h index 419a3f9d158f..a8c0cabe7e41 100644 --- a/cobalt/media/base/sbplayer_pipeline.h +++ b/cobalt/media/base/sbplayer_pipeline.h @@ -65,13 +65,15 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, bool allow_resume_after_suspend, int max_audio_samples_per_write, bool force_punch_out_by_default, +#if SB_API_VERSION >= 15 TimeDelta audio_write_duration_local, - TimeDelta audio_write_duration_remote, MediaLog* media_log, + TimeDelta audio_write_duration_remote, +#endif // SB_API_VERSION >= 15 + MediaLog* media_log, MediaMetricsProvider* media_metrics_provider, DecodeTargetProvider* decode_target_provider); ~SbPlayerPipeline() override; - void Suspend() override; // TODO: This is temporary for supporting background media playback. // Need to be removed with media refactor. @@ -323,6 +325,7 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, DecodeTargetProvider* decode_target_provider_; +#if SB_API_VERSION >= 15 const TimeDelta audio_write_duration_local_; const TimeDelta audio_write_duration_remote_; @@ -331,6 +334,16 @@ class MEDIA_EXPORT SbPlayerPipeline : public Pipeline, // is, which simplifies the implementation across multiple Starboard versions. TimeDelta audio_write_duration_; TimeDelta audio_write_duration_for_preroll_ = audio_write_duration_; +#else // SB_API_VERSION >= 15 + // Read audio from the stream if |timestamp_of_last_written_audio_| is less + // than |seek_time_| + |audio_write_duration_for_preroll_|, this effectively + // allows 10 seconds of audio to be written to the SbPlayer after playback + // startup or seek. + TimeDelta audio_write_duration_for_preroll_ = TimeDelta::FromSeconds(10); + // Don't read audio from the stream more than |audio_write_duration_| ahead of + // the current media time during playing. + TimeDelta audio_write_duration_ = TimeDelta::FromSeconds(1); +#endif // SB_API_VERSION >= 15 // Only call GetMediaTime() from OnNeedData if it has been // |kMediaTimeCheckInterval| since the last call to GetMediaTime(). static constexpr TimeDelta kMediaTimeCheckInterval = diff --git a/cobalt/media/media_module.cc b/cobalt/media/media_module.cc index 4092416b25aa..f245ac43a9e3 100644 --- a/cobalt/media/media_module.cc +++ b/cobalt/media/media_module.cc @@ -200,6 +200,7 @@ bool MediaModule::SetConfiguration(const std::string& name, int32 value) { LOG(INFO) << (value ? "Enabling" : "Disabling") << " media metrics collection."; return true; +#if SB_API_VERSION >= 15 } else if (name == "AudioWriteDurationLocal" && value > 0) { audio_write_duration_local_ = base::TimeDelta::FromMicroseconds(value); LOG(INFO) << "Set AudioWriteDurationLocal to " @@ -210,14 +211,13 @@ bool MediaModule::SetConfiguration(const std::string& name, int32 value) { LOG(INFO) << "Set AudioWriteDurationRemote to " << audio_write_duration_remote_.InMicroseconds(); return true; +#endif // SB_API_VERSION >= 15 } else if (name == "PlayerConfiguration.DecodeToTexturePreferred") { if (sbplayer_interface_->SetDecodeToTexturePreferred(value)) { LOG(INFO) << "Set DecodeToTexturePreferred to " << (value ? "true" : "false"); return true; } - - } else if (name == "AsyncReleaseMediaCodecBridge") { const StarboardExtensionMediaSettingsApi* media_settings_api = static_cast( @@ -265,7 +265,10 @@ std::unique_ptr MediaModule::CreateWebMediaPlayer( base::Unretained(this)), client, this, options_.allow_resume_after_suspend, max_audio_samples_per_write_, force_punch_out_by_default_, - audio_write_duration_local_, audio_write_duration_remote_, &media_log_)); +#if SB_API_VERSION >= 15 + audio_write_duration_local_, audio_write_duration_remote_, +#endif // SB_API_VERSION >= 15 + &media_log_)); } void MediaModule::Suspend() { diff --git a/cobalt/media/media_module.h b/cobalt/media/media_module.h index 591e95474345..f29973a1f615 100644 --- a/cobalt/media/media_module.h +++ b/cobalt/media/media_module.h @@ -133,10 +133,12 @@ class MediaModule : public WebMediaPlayerFactory, // previous behavior. bool force_punch_out_by_default_ = false; +#if SB_API_VERSION >= 15 base::TimeDelta audio_write_duration_local_ = base::TimeDelta::FromMicroseconds(kSbPlayerWriteDurationLocal); base::TimeDelta audio_write_duration_remote_ = base::TimeDelta::FromMicroseconds(kSbPlayerWriteDurationRemote); +#endif // SB_API_VERSION >= 15 DecoderBufferAllocator decoder_buffer_allocator_; }; diff --git a/cobalt/media/player/web_media_player_impl.cc b/cobalt/media/player/web_media_player_impl.cc index 92af6fed21f4..62189b7b3061 100644 --- a/cobalt/media/player/web_media_player_impl.cc +++ b/cobalt/media/player/web_media_player_impl.cc @@ -104,15 +104,17 @@ typedef base::Callback, int)> OnNeedKeyCB; - WebMediaPlayerImpl::WebMediaPlayerImpl( SbPlayerInterface* interface, PipelineWindow window, const Pipeline::GetDecodeTargetGraphicsContextProviderFunc& get_decode_target_graphics_context_provider_func, WebMediaPlayerClient* client, WebMediaPlayerDelegate* delegate, bool allow_resume_after_suspend, int max_audio_samples_per_write, - bool force_punch_out_by_default, base::TimeDelta audio_write_duration_local, + bool force_punch_out_by_default, +#if SB_API_VERSION >= 15 + base::TimeDelta audio_write_duration_local, base::TimeDelta audio_write_duration_remote, +#endif // SB_API_VERSION >= 15 ::media::MediaLog* const media_log) : pipeline_thread_("media_pipeline"), network_state_(WebMediaPlayer::kNetworkStateEmpty), @@ -142,9 +144,11 @@ WebMediaPlayerImpl::WebMediaPlayerImpl( interface, window, pipeline_thread_.task_runner(), get_decode_target_graphics_context_provider_func, allow_resume_after_suspend_, max_audio_samples_per_write_, - force_punch_out_by_default_, audio_write_duration_local, - audio_write_duration_remote, media_log_, &media_metrics_provider_, - decode_target_provider_.get()); + force_punch_out_by_default_, +#if SB_API_VERSION >= 15 + audio_write_duration_local, audio_write_duration_remote, +#endif // SB_API_VERSION >= 15 + media_log_, &media_metrics_provider_, decode_target_provider_.get()); // Also we want to be notified of thread destruction. base::CurrentThread::Get()->AddDestructionObserver(this); diff --git a/cobalt/media/player/web_media_player_impl.h b/cobalt/media/player/web_media_player_impl.h index 205080a2f693..6d4c55f39f9c 100644 --- a/cobalt/media/player/web_media_player_impl.h +++ b/cobalt/media/player/web_media_player_impl.h @@ -112,8 +112,10 @@ class WebMediaPlayerImpl : public WebMediaPlayer, bool allow_resume_after_suspend, int max_audio_samples_per_write, bool force_punch_out_by_default, +#if SB_API_VERSION >= 15 base::TimeDelta audio_write_duration_local, base::TimeDelta audio_write_duration_remote, +#endif // SB_API_VERSION >= 15 ::media::MediaLog* const media_log); ~WebMediaPlayerImpl() override; diff --git a/cobalt/media/sandbox/format_guesstimator.cc b/cobalt/media/sandbox/format_guesstimator.cc index 843bbd915043..e34c7643b127 100644 --- a/cobalt/media/sandbox/format_guesstimator.cc +++ b/cobalt/media/sandbox/format_guesstimator.cc @@ -37,6 +37,7 @@ #include "media/filters/chunk_demuxer.h" #include "net/base/filename_util.h" #include "net/base/url_util.h" +#include "starboard/common/file.h" #include "starboard/memory.h" #include "starboard/types.h" #include "ui/gfx/geometry/size.h" @@ -81,7 +82,7 @@ base::FilePath ResolvePath(const std::string& path) { base::PathService::Get(base::DIR_TEST_DATA, &content_path); result = content_path.Append(result); } - if (SbFileCanOpen(result.value().c_str(), kSbFileOpenOnly | kSbFileRead)) { + if (starboard::FileCanOpen(result.value().c_str(), O_RDONLY)) { return result; } LOG(WARNING) << "Failed to resolve path \"" << path << "\" as \"" @@ -141,7 +142,7 @@ FormatGuesstimator::FormatGuesstimator(const std::string& path_or_url, return; } base::FilePath path = ResolvePath(path_or_url); - if (path.empty() || !SbFileCanOpen(path.value().c_str(), kSbFileRead)) { + if (path.empty() || !starboard::FileCanOpen(path.value().c_str(), O_RDONLY)) { return; } InitializeAsAdaptive(path, media_module); diff --git a/cobalt/network/network_module.cc b/cobalt/network/network_module.cc index 3a0b02fc51bc..8b2ec4558009 100644 --- a/cobalt/network/network_module.cc +++ b/cobalt/network/network_module.cc @@ -120,6 +120,20 @@ void NetworkModule::SetEnableQuicFromPersistentSettings() { } } +void NetworkModule::SetEnableHttp2FromPersistentSettings() { + // Called on initialization and when the persistent setting is changed. + if (options_.persistent_settings != nullptr) { + base::Value value; + options_.persistent_settings->Get(kHttp2EnabledPersistentSettingsKey, + &value); + bool enable_http2 = value.GetIfBool().value_or(true); + task_runner()->PostTask( + FROM_HERE, + base::Bind(&URLRequestContext::SetEnableHttp2, + base::Unretained(url_request_context_.get()), enable_http2)); + } +} + void NetworkModule::SetEnableHttp3FromPersistentSettings() { // Called on initialization and when the persistent setting is changed. if (options_.persistent_settings != nullptr) { @@ -233,6 +247,7 @@ void NetworkModule::Initialize(const std::string& user_agent_string, url_request_context_.get(), thread_.get()); SetEnableQuicFromPersistentSettings(); + SetEnableHttp2FromPersistentSettings(); SetEnableHttp3FromPersistentSettings(); } diff --git a/cobalt/network/network_module.h b/cobalt/network/network_module.h index 01f13fe8a2a0..e0151d690139 100644 --- a/cobalt/network/network_module.h +++ b/cobalt/network/network_module.h @@ -59,6 +59,7 @@ enum ClientHintHeadersCallType : int32_t { constexpr int32_t kEnabledClientHintHeaders = (kCallTypeLoader | kCallTypeXHR); const char kQuicEnabledPersistentSettingsKey[] = "QUICEnabled"; +const char kHttp2EnabledPersistentSettingsKey[] = "HTTP2Enabled"; const char kHttp3EnabledPersistentSettingsKey[] = "HTTP3Enabled"; class NetworkSystem; @@ -130,6 +131,7 @@ class NetworkModule : public base::CurrentThread::DestructionObserver { void SetProxy(const std::string& custom_proxy_rules); void SetEnableQuicFromPersistentSettings(); + void SetEnableHttp2FromPersistentSettings(); void SetEnableHttp3FromPersistentSettings(); // Adds the Client Hint Headers to the provided URLFetcher if enabled. diff --git a/cobalt/network/switches.cc b/cobalt/network/switches.cc index d7280d10c4fd..c547ce07195f 100644 --- a/cobalt/network/switches.cc +++ b/cobalt/network/switches.cc @@ -44,6 +44,9 @@ const char kDisableInAppDial[] = "disable_in_app_dial"; // Switch to disable use of the Quic network protocol. const char kDisableQuic[] = "disable_quic"; +// Switch to disable use of the HTTP/2 (SPDY) network protocol. +const char kDisableHttp2[] = "disable_h2"; + } // namespace switches } // namespace network diff --git a/cobalt/network/switches.h b/cobalt/network/switches.h index 6def908bdb6c..83b842bc879b 100644 --- a/cobalt/network/switches.h +++ b/cobalt/network/switches.h @@ -28,6 +28,7 @@ extern const char kMaxNetworkDelayHelp[]; extern const char kDisableInAppDial[]; #endif // ENABLE_DEBUG_COMMAND_LINE_SWITCHES extern const char kDisableQuic[]; +extern const char kDisableHttp2[]; } // namespace switches } // namespace network diff --git a/cobalt/network/url_request_context.cc b/cobalt/network/url_request_context.cc index 325d81b162eb..666cf4fe8b06 100644 --- a/cobalt/network/url_request_context.cc +++ b/cobalt/network/url_request_context.cc @@ -209,17 +209,17 @@ URLRequestContext::URLRequestContext( quic::ParsedQuicVersionVector{quic::ParsedQuicVersion::Q046()}; url_request_context_builder->set_quic_context(std::move(quic_context)); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); bool quic_enabled = - configuration::Configuration::GetInstance()->CobaltEnableQuic(); - if (quic_enabled) { - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - quic_enabled = !command_line->HasSwitch(switches::kDisableQuic); - } + configuration::Configuration::GetInstance()->CobaltEnableQuic() && + !command_line->HasSwitch(switches::kDisableQuic); + bool spdy_enabled = !command_line->HasSwitch(switches::kDisableHttp2); - url_request_context_builder->SetSpdyAndQuicEnabled(/*spdy_enabled=*/true, + url_request_context_builder->SetSpdyAndQuicEnabled(spdy_enabled, quic_enabled); net::HttpNetworkSessionParams params; + params.enable_http2 = spdy_enabled; params.enable_quic = quic_enabled; params.use_quic_for_unknown_origins = quic_enabled; @@ -329,7 +329,20 @@ void URLRequestContext::SetProxy(const std::string& proxy_rules) { void URLRequestContext::SetEnableQuic(bool enable_quic) { DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); - url_request_context_->http_network_session()->SetEnableQuic(enable_quic); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + bool quic_commandline_enabled = + !command_line->HasSwitch(switches::kDisableQuic); + url_request_context_->http_network_session()->SetEnableQuic( + enable_quic && quic_commandline_enabled); +} + +void URLRequestContext::SetEnableHttp2(bool enable_http2) { + DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + bool http2_commandline_enabled = + !command_line->HasSwitch(switches::kDisableHttp2); + url_request_context_->http_network_session()->SetEnableHttp2( + enable_http2 && http2_commandline_enabled); } bool URLRequestContext::using_http_cache() { return using_http_cache_; } diff --git a/cobalt/network/url_request_context.h b/cobalt/network/url_request_context.h index dd987e472bf3..4f93aface53c 100644 --- a/cobalt/network/url_request_context.h +++ b/cobalt/network/url_request_context.h @@ -60,6 +60,7 @@ class URLRequestContext { void SetProxy(const std::string& custom_proxy_rules); void SetEnableQuic(bool enable_quic); + void SetEnableHttp2(bool enable_http2); bool using_http_cache(); diff --git a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.cc b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.cc index e108d495b346..a8054f90e262 100644 --- a/cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.cc +++ b/cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.cc @@ -7,6 +7,9 @@ #include "cobalt/renderer/rasterizer/skia/skia/src/ports/SkOSFile_cobalt.h" +#include +#include + #include "SkString.h" #include "SkTFitsIn.h" #include "SkTemplates.h" @@ -16,6 +19,8 @@ #include "base/files/file_util.h" #include "base/optional.h" #include "base/path_service.h" +#include "starboard/common/file.h" +#include "starboard/common/file_wrapper.h" // Implement functionality declared in SkOSFile.h via primitives provided // by Chromium. In doing this, we need only ensure that support for Chromium @@ -23,25 +28,25 @@ namespace { -SbFile ToSbFile(FILE* sk_file) { +FilePtr ToFilePtr(FILE* sk_file) { // PlatformFile is a pointer type in Starboard, so we cannot use static_cast // from intptr_t. - return reinterpret_cast(sk_file); + return reinterpret_cast(sk_file); } -FILE* ToFILE(SbFile starboard_file) { +FILE* ToFILE(FilePtr starboard_file) { return reinterpret_cast(starboard_file); } -int ToSbFileFlags(SkFILE_Flags sk_flags) { +int ToFileFlags(SkFILE_Flags sk_flags) { int flags = 0; if (sk_flags & kRead_SkFILE_Flag) { if (sk_flags & kWrite_SkFILE_Flag) { - flags |= kSbFileWrite; + flags |= O_WRONLY; } - flags |= kSbFileOpenOnly | kSbFileRead; + flags |= O_RDONLY; } else if (sk_flags & kWrite_SkFILE_Flag) { - flags |= kSbFileOpenAlways | kSbFileWrite; + flags |= O_CREAT | O_WRONLY; } return flags; } @@ -49,68 +54,66 @@ int ToSbFileFlags(SkFILE_Flags sk_flags) { } // namespace FILE* sk_fopen(const char path[], SkFILE_Flags sk_flags) { - SbFile starboard_file = SbFileOpen(path, ToSbFileFlags(sk_flags), NULL, NULL); - // TODO: temporarily replace with kSbFileInvalid, will be deprecated with - // SBFile. - if (starboard_file == kSbFileInvalid) { + FilePtr file = file_open(path, ToFileFlags(sk_flags)); + if (!file || file->fd < 0) { return nullptr; } - return ToFILE(starboard_file); + return ToFILE(file); } void sk_fclose(FILE* sk_file) { SkASSERT(sk_file); - SbFileClose(ToSbFile(sk_file)); + int ret = file_close(ToFilePtr(sk_file)); } size_t sk_fgetsize(FILE* sk_file) { SkASSERT(sk_file); - SbFile file = ToSbFile(sk_file); + FilePtr file = ToFilePtr(sk_file); // Save current position so we can restore it. - int64_t current_position = SbFileSeek(file, kSbFileFromCurrent, 0); + int64_t current_position = lseek(file->fd, 0, SEEK_CUR); if (current_position < 0) { return 0; } // Find the file size by seeking to the end. - int64_t size = SbFileSeek(file, kSbFileFromEnd, 0); + int64_t size = lseek(file->fd, 0, SEEK_END); if (size < 0) { size = 0; } // Restore original file position. - SbFileSeek(file, kSbFileFromBegin, current_position); + lseek(file->fd, current_position, SEEK_SET); return size; } size_t sk_fwrite(const void* buffer, size_t byteCount, FILE* sk_file) { SkASSERT(sk_file); - SbFile file = ToSbFile(sk_file); + FilePtr file = ToFilePtr(sk_file); int result = - SbFileWrite(file, reinterpret_cast(buffer), byteCount); + write(file->fd, reinterpret_cast(buffer), byteCount); base::RecordFileWriteStat(result); return result; } void sk_fflush(FILE* sk_file) { SkASSERT(sk_file); - SbFile file = ToSbFile(sk_file); - SbFileFlush(file); + FilePtr file = ToFilePtr(sk_file); + fsync(file->fd); } bool sk_fseek(FILE* sk_file, size_t position) { SkASSERT(sk_file); - SbFile file = ToSbFile(sk_file); - int64_t new_position = SbFileSeek(file, kSbFileFromBegin, position); + FilePtr file = ToFilePtr(sk_file); + int64_t new_position = lseek(file->fd, position, SEEK_SET); return new_position == position; } size_t sk_ftell(FILE* sk_file) { SkASSERT(sk_file); - SbFile file = ToSbFile(sk_file); - return SbFileSeek(file, kSbFileFromCurrent, 0); + FilePtr file = ToFilePtr(sk_file); + return lseek(file->fd, 0, SEEK_CUR); } void* sk_fmmap(FILE* sk_file, size_t* length) { @@ -154,28 +157,29 @@ bool sk_mkdir(const char* path) { void sk_fsync(FILE* f) { SkASSERT(f); - SbFile file = ToSbFile(f); + FilePtr file = ToFilePtr(f); // Technically, flush doesn't have to call sync... but this is the best // effort we can make. - SbFileFlush(file); + fsync(file->fd); } size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) { SkASSERT(file); - SbFile starboard_file = ToSbFile(file); + FilePtr starboard_file = ToFilePtr(file); - int original_position = SbFileSeek(starboard_file, kSbFileFromCurrent, 0); + int original_position = lseek(starboard_file->fd, 0, SEEK_CUR); if (original_position < 0) { return SIZE_MAX; } - int position = SbFileSeek(starboard_file, kSbFileFromBegin, offset); + int position = lseek(starboard_file->fd, offset, SEEK_SET); int result = 0; if (position == offset) { - result = SbFileReadAll(starboard_file, reinterpret_cast(buffer), + result = + starboard::ReadAll(starboard_file->fd, reinterpret_cast(buffer), static_cast(count)); } - position = SbFileSeek(starboard_file, kSbFileFromBegin, original_position); + position = lseek(starboard_file->fd, original_position, SEEK_SET); if (result < 0 || position < 0) { return SIZE_MAX; } else { @@ -185,7 +189,7 @@ size_t sk_qread(FILE* file, void* buffer, size_t count, size_t offset) { size_t sk_fread(void* buffer, size_t byteCount, FILE* file) { SkASSERT(file); - SbFile starboard_file = ToSbFile(file); - return SbFileReadAll(starboard_file, reinterpret_cast(buffer), - byteCount); + FilePtr starboard_file = ToFilePtr(file); + return starboard::ReadAll(starboard_file->fd, reinterpret_cast(buffer), + byteCount); } diff --git a/cobalt/web/agent.cc b/cobalt/web/agent.cc index 39b71ef410ed..b987b909dd4e 100644 --- a/cobalt/web/agent.cc +++ b/cobalt/web/agent.cc @@ -585,8 +585,9 @@ void Agent::Run(const Options& options, InitializeCallback initialize_callback, DestructionObserver* destruction_observer) { // Start the dedicated thread and create the internal implementation // object on that thread. - if (!thread_.StartWithOptions(base::Thread::Options(options.thread_priority))) - return; + base::Thread::Options thread_options(options.thread_priority); + thread_options.stack_size = options.stack_size; + if (!thread_.StartWithOptions(std::move(thread_options))) return; DCHECK(task_runner()); // Registers service worker thread as a watchdog client. diff --git a/cobalt/web/testing/mock_user_agent_platform_info.h b/cobalt/web/testing/mock_user_agent_platform_info.h index 16b37927a247..c8eeb2295448 100644 --- a/cobalt/web/testing/mock_user_agent_platform_info.h +++ b/cobalt/web/testing/mock_user_agent_platform_info.h @@ -40,6 +40,11 @@ class MockUserAgentPlatformInfo : public web::UserAgentPlatformInfo { base::Optional original_design_manufacturer() const override { return optional_empty_string_; } +#if SB_API_VERSION < 15 + SbSystemDeviceType device_type() const override { + return kSbSystemDeviceTypeUnknown; + } +#endif const std::string& device_type_string() const override { return empty_string_; } diff --git a/cobalt/web/user_agent_platform_info.h b/cobalt/web/user_agent_platform_info.h index e75faa902fa6..f523addd888d 100644 --- a/cobalt/web/user_agent_platform_info.h +++ b/cobalt/web/user_agent_platform_info.h @@ -32,6 +32,9 @@ class UserAgentPlatformInfo { virtual const std::string& starboard_version() const = 0; virtual const std::string& os_name_and_version() const = 0; virtual base::Optional original_design_manufacturer() const = 0; +#if SB_API_VERSION < 15 + virtual SbSystemDeviceType device_type() const = 0; +#endif virtual const std::string& device_type_string() const = 0; virtual base::Optional chipset_model_number() const = 0; virtual base::Optional model_year() const = 0; diff --git a/components/update_client/action_runner.cc b/components/update_client/action_runner.cc index b456f138e6ce..02dc1a53c1a7 100644 --- a/components/update_client/action_runner.cc +++ b/components/update_client/action_runner.cc @@ -4,6 +4,8 @@ #include "components/update_client/action_runner.h" +#include + #include #include #include @@ -42,11 +44,11 @@ void CleanupDirectory(base::FilePath& dir) { if (info.IsDirectory()) { directories.push(path.value()); } else { - SbFileDelete(path.value().c_str()); + unlink(path.value().c_str()); } } while (!directories.empty()) { - SbFileDelete(directories.top().c_str()); + rmdir(directories.top().c_str()); directories.pop(); } } diff --git a/components/update_client/url_fetcher_downloader.cc b/components/update_client/url_fetcher_downloader.cc index b4949468196f..ad7f64481d10 100644 --- a/components/update_client/url_fetcher_downloader.cc +++ b/components/update_client/url_fetcher_downloader.cc @@ -41,11 +41,11 @@ void CleanupDirectory(base::FilePath& dir) { if (info.IsDirectory()) { directories.push(path.value()); } else { - SbFileDelete(path.value().c_str()); + unlink(path.value().c_str()); } } while (!directories.empty()) { - SbFileDelete(directories.top().c_str()); + rmdir(directories.top().c_str()); directories.pop(); } } diff --git a/media/base/starboard_utils.cc b/media/base/starboard_utils.cc index efa5411d9b10..9c3adabdf1f6 100644 --- a/media/base/starboard_utils.cc +++ b/media/base/starboard_utils.cc @@ -75,8 +75,10 @@ SbMediaAudioCodec MediaAudioCodecToSbMediaAudioCodec(AudioCodec codec) { return kSbMediaAudioCodecFlac; case AudioCodec::kPCM: return kSbMediaAudioCodecPcm; +#if SB_API_VERSION >= 15 case AudioCodec::kIAMF: return kSbMediaAudioCodecIamf; +#endif // SB_API_VERSION >= 15 default: // Cobalt only supports a subset of audio codecs defined by Chromium. DLOG(ERROR) << "Unsupported audio codec " << GetCodecName(codec); @@ -124,10 +126,17 @@ SbMediaAudioStreamInfo MediaAudioConfigToSbMediaAudioStreamInfo( MediaAudioCodecToSbMediaAudioCodec(audio_decoder_config.codec()); audio_stream_info.mime = mime_type; +#if SB_API_VERSION < 15 + audio_stream_info.format_tag = 0x00ff; +#endif // SB_API_VERSION < 15 audio_stream_info.number_of_channels = ChannelLayoutToChannelCount(audio_decoder_config.channel_layout()); audio_stream_info.samples_per_second = audio_decoder_config.samples_per_second(); +#if SB_API_VERSION < 15 + audio_stream_info.average_bytes_per_second = 1; + audio_stream_info.block_alignment = 4; +#endif // SB_API_VERSION < 15 audio_stream_info.bits_per_sample = audio_decoder_config.bits_per_channel(); const auto& extra_data = audio_stream_info.codec == kSbMediaAudioCodecAac diff --git a/net/dns/address_sorter_posix.cc b/net/dns/address_sorter_posix.cc index 0f4afb74871c..622d4da49bdd 100644 --- a/net/dns/address_sorter_posix.cc +++ b/net/dns/address_sorter_posix.cc @@ -140,7 +140,13 @@ const AddressSorterPosix::PolicyEntry kDefaultPrecedenceTable[] = { // ::/0 -- any {{}, 0, 40}, // ::ffff:0:0/96 -- IPv4 mapped +#if defined(STARBOARD) + // Cobalt currently prioritizes IPv4 addresses higher, as + // suggested in section 10.3 of RFC3484 + {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}, 96, 100}, +#else {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF}, 96, 35}, +#endif // 2002::/16 -- 6to4 {{ 0x20, diff --git a/net/dns/address_sorter_posix_unittest.cc b/net/dns/address_sorter_posix_unittest.cc index a4383aefc6a6..4d35ea5479c4 100644 --- a/net/dns/address_sorter_posix_unittest.cc +++ b/net/dns/address_sorter_posix_unittest.cc @@ -386,7 +386,11 @@ TEST_P(AddressSorterPosixSyncOrAsyncTest, Rule6) { AddMapping("2001::1", "2001::10"); // Teredo const char* const addresses[] = {"2001::1", "::ffff:1234:1", "ff32::1", "::1", nullptr}; +#if defined(STARBOARD) + const int order[] = { 1, 3, 2, 0, -1 }; +#else const int order[] = { 3, 2, 1, 0, -1 }; +#endif Verify(addresses, order); } diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 093e8a5486f4..92b40b6fd8e8 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -373,6 +373,25 @@ void HttpNetworkSession::DisableQuic() { void HttpNetworkSession::SetEnableQuic(bool enable_quic) { params_.enable_quic = enable_quic; } +void HttpNetworkSession::SetEnableHttp2(bool enable_http2) { + if (params_.enable_http2 == enable_http2) { + return; + } + params_.enable_http2 = enable_http2; + + if (params_.enable_http2) { + next_protos_.push_back(kProtoHTTP2); + if (base::FeatureList::IsEnabled(features::kAlpsForHttp2)) { + // Enable ALPS for HTTP/2 with empty data. + application_settings_[kProtoHTTP2] = {}; + } + } else { + if (next_protos_.back() == kProtoHTTP2) { + next_protos_.pop_back(); + } + application_settings_.erase(kProtoHTTP2); + } +} bool HttpNetworkSession::UseQuicForUnknownOrigin() const { return params_.use_quic_for_unknown_origins; diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 7636bb3e85dc..813d86cda427 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -315,6 +315,7 @@ class NET_EXPORT HttpNetworkSession { #if defined(STARBOARD) void SetEnableQuic(bool enable_quic); + void SetEnableHttp2(bool enable_http2); // Whether to try QUIC connection for origins without alt-svc on record. bool UseQuicForUnknownOrigin() const; diff --git a/starboard/android/apk/apk_sources.gni b/starboard/android/apk/apk_sources.gni index a0ed8ac617fe..dd4e91c8413f 100644 --- a/starboard/android/apk/apk_sources.gni +++ b/starboard/android/apk/apk_sources.gni @@ -18,15 +18,21 @@ apk_sources = [ "//starboard/android/apk/app/src/app/java/dev/cobalt/app/CobaltApplication.java", "//starboard/android/apk/app/src/app/java/dev/cobalt/app/MainActivity.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloader.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloaderDefault.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkLoader.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/AudioPermissionRequester.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CaptionSettings.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltA11yHelper.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltActivity.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltHttpHelper.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltService.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltSystemConfigChangeReceiver.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltTextToSpeechHelper.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/CrashContextUpdateHandler.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/ErrorDialog.java", + "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaImage.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NetworkStatus.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/NullCobaltFactory.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/PlatformError.java", @@ -34,11 +40,8 @@ apk_sources = [ "//starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfo.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/libraries/services/clientloginfo/ClientLogInfoModule.java", - "//starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkLoader.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioTrackBridge.java", - "//starboard/android/apk/app/src/main/java/dev/cobalt/media/CaptionSettings.java", - "//starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/Log.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridge.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecBridgeBuilder.java", @@ -46,7 +49,6 @@ apk_sources = [ "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaCodecUtil.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaDrmBridge.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaFormatBuilder.java", - "//starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaImage.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/VideoFrameReleaseTimeHelper.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/VideoSurfaceTexture.java", "//starboard/android/apk/app/src/main/java/dev/cobalt/media/VideoSurfaceView.java", diff --git a/starboard/android/apk/app/src/app/java/dev/cobalt/app/MainActivity.java b/starboard/android/apk/app/src/app/java/dev/cobalt/app/MainActivity.java index 680eb4674dd0..20fbcdf4b4a9 100644 --- a/starboard/android/apk/app/src/app/java/dev/cobalt/app/MainActivity.java +++ b/starboard/android/apk/app/src/app/java/dev/cobalt/app/MainActivity.java @@ -16,11 +16,11 @@ import android.app.Activity; import android.app.Service; +import dev.cobalt.coat.ArtworkDownloaderDefault; import dev.cobalt.coat.CobaltActivity; import dev.cobalt.coat.CobaltService; import dev.cobalt.coat.StarboardBridge; import dev.cobalt.libraries.services.clientloginfo.ClientLogInfoModule; -import dev.cobalt.media.ArtworkDownloaderDefault; import dev.cobalt.util.Holder; /** diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloader.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloader.java similarity index 96% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloader.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloader.java index 7bb294d3c025..6b2f0132b165 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloader.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloader.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; /** * Interface to download artwork (Bitmap) from a URL, intended for use in media session metadata. diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloaderDefault.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloaderDefault.java similarity index 96% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloaderDefault.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloaderDefault.java index 8cc99c22a1a8..023ec05ce6eb 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkDownloaderDefault.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkDownloaderDefault.java @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; -import static dev.cobalt.media.Log.TAG; +import static dev.cobalt.util.Log.TAG; import android.graphics.Bitmap; import android.graphics.BitmapFactory; diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkLoader.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkLoader.java similarity index 99% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkLoader.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkLoader.java index 1742a435fe37..c2c52b9f928f 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/ArtworkLoader.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/ArtworkLoader.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; import android.graphics.Bitmap; import android.os.Handler; diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/CaptionSettings.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/CaptionSettings.java similarity index 98% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/CaptionSettings.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/CaptionSettings.java index 81ed4ee77e88..6f5a473879d7 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/CaptionSettings.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/CaptionSettings.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; import android.view.accessibility.CaptioningManager; import dev.cobalt.util.UsedByNative; diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java similarity index 99% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java index e3541b56f989..c10d19798cb1 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/CobaltMediaSession.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/CobaltMediaSession.java @@ -12,9 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; -import static dev.cobalt.media.Log.TAG; +import static dev.cobalt.util.Log.TAG; import android.app.Activity; import android.content.Context; @@ -50,7 +50,7 @@ public class CobaltMediaSession private AudioFocusRequest audioFocusRequest; - interface UpdateVolumeListener { + public interface UpdateVolumeListener { /** Called when there is a change in audio focus. */ void onUpdateVolume(float gain); } diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaImage.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaImage.java similarity index 97% rename from starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaImage.java rename to starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaImage.java index 899dc224ab2b..70322593b8da 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/MediaImage.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/MediaImage.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dev.cobalt.media; +package dev.cobalt.coat; import dev.cobalt.util.UsedByNative; diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java index fe7f9c80a9ad..c0b7b209695b 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/coat/StarboardBridge.java @@ -38,11 +38,7 @@ import android.view.accessibility.AccessibilityManager; import android.view.accessibility.CaptioningManager; import androidx.annotation.Nullable; -import dev.cobalt.media.ArtworkDownloader; import dev.cobalt.media.AudioOutputManager; -import dev.cobalt.media.CaptionSettings; -import dev.cobalt.media.CobaltMediaSession; -import dev.cobalt.media.MediaImage; import dev.cobalt.util.DisplayUtil; import dev.cobalt.util.Holder; import dev.cobalt.util.Log; diff --git a/starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java b/starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java index 9aba9c3ab797..13fdf700a525 100644 --- a/starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java +++ b/starboard/android/apk/app/src/main/java/dev/cobalt/media/AudioOutputManager.java @@ -25,6 +25,7 @@ import android.media.AudioTrack; import android.os.Build; import androidx.annotation.RequiresApi; +import dev.cobalt.coat.CobaltMediaSession; import dev.cobalt.util.Log; import dev.cobalt.util.UsedByNative; import java.util.ArrayList; diff --git a/starboard/android/shared/BUILD.gn b/starboard/android/shared/BUILD.gn index 9a248f25f287..d7343f02bb34 100644 --- a/starboard/android/shared/BUILD.gn +++ b/starboard/android/shared/BUILD.gn @@ -396,6 +396,7 @@ static_library("starboard_platform") { "speech_synthesis_internal.cc", "speech_synthesis_is_supported.cc", "speech_synthesis_speak.cc", + "system_get_device_type.cc", "system_get_extensions.cc", "system_get_locale_id.cc", "system_get_path.cc", diff --git a/starboard/android/shared/accessibility_get_caption_settings.cc b/starboard/android/shared/accessibility_get_caption_settings.cc index f5f9fe493771..3057366d1ae5 100644 --- a/starboard/android/shared/accessibility_get_caption_settings.cc +++ b/starboard/android/shared/accessibility_get_caption_settings.cc @@ -118,7 +118,7 @@ bool GetCaptionSettings(SbAccessibilityCaptionSettings* caption_settings) { ScopedLocalJavaRef j_caption_settings( env->CallStarboardObjectMethodOrAbort( - "getCaptionSettings", "()Ldev/cobalt/media/CaptionSettings;")); + "getCaptionSettings", "()Ldev/cobalt/coat/CaptionSettings;")); jfloat font_scale = env->GetFloatFieldOrAbort(j_caption_settings.Get(), "fontScale", "F"); diff --git a/starboard/android/shared/android_main.cc b/starboard/android/shared/android_main.cc index d091b0bf5f53..011611739aaa 100644 --- a/starboard/android/shared/android_main.cc +++ b/starboard/android/shared/android_main.cc @@ -13,14 +13,16 @@ // limitations under the License. #include +#include #include +#include +#include #include "game-activity/GameActivity.h" #include "starboard/android/shared/application_android.h" #include "starboard/android/shared/jni_env_ext.h" #include "starboard/android/shared/jni_utils.h" #include "starboard/android/shared/log_internal.h" -#include "starboard/common/atomic.h" #include "starboard/common/file.h" #include "starboard/common/semaphore.h" #include "starboard/common/string.h" @@ -40,7 +42,7 @@ namespace starboard { namespace android { namespace shared { -atomic_bool g_block_swapbuffers; +std::atomic_bool g_block_swapbuffers{false}; namespace { @@ -54,7 +56,7 @@ Semaphore* g_app_created_semaphore = nullptr; // Safeguard to avoid sending AndroidCommands either when there is no instance // of the Starboard application, or after the run loop has exited and the // ALooper receiving the commands is no longer being polled. -atomic_bool g_app_running; +std::atomic_bool g_app_running{false}; std::vector GetArgs() { std::vector args; @@ -122,52 +124,49 @@ bool CopyDirContents(const std::string& src_dir_path, std::string filename(filename_buffer.begin(), filename_buffer.end()); std::string path_to_src_file = src_dir_path + kSbFileSepString + filename; - SbFile src_file = - SbFileOpen(path_to_src_file.c_str(), kSbFileOpenOnly | kSbFileRead, - nullptr, nullptr); - if (src_file == kSbFileInvalid) { + int src_file = open(path_to_src_file.c_str(), O_RDONLY, S_IRUSR | S_IWUSR); + if (!IsValid(src_file)) { SB_LOG(WARNING) << "Failed to open file=" << path_to_src_file; return false; } - SbFileInfo info; - if (!SbFileGetInfo(src_file, &info)) { + struct stat info; + if (fstat(src_file, &info)) { SB_LOG(WARNING) << "Failed to get info for file=" << path_to_src_file; - SbFileClose(src_file); + close(src_file); return false; } - int file_size = static_cast(info.size); + int file_size = static_cast(info.st_size); // Read in bytes from src file char file_contents_buffer[file_size]; - int read = SbFileReadAll(src_file, file_contents_buffer, file_size); + int read = ReadAll(src_file, file_contents_buffer, file_size); if (read == -1) { - SB_LOG(WARNING) << "SbFileReadAll failed for file=" << path_to_src_file; + SB_LOG(WARNING) << "ReadAll failed for file=" << path_to_src_file; return false; } const std::string file_contents = std::string(file_contents_buffer, file_size); - SbFileClose(src_file); + close(src_file); // Write bytes out to dst file std::string path_to_dst_file = dst_dir_path; path_to_dst_file.append(kSbFileSepString); path_to_dst_file.append(filename); - SbFile dst_file = - SbFileOpen(path_to_dst_file.c_str(), kSbFileCreateAlways | kSbFileWrite, - NULL, NULL); - if (dst_file == kSbFileInvalid) { + int dst_file = open(path_to_dst_file.c_str(), O_CREAT | O_TRUNC | O_WRONLY, + S_IRUSR | S_IWUSR); + if (!IsValid(dst_file)) { SB_LOG(WARNING) << "Failed to open file=" << path_to_dst_file; return false; } - int wrote = SbFileWriteAll(dst_file, file_contents.c_str(), file_size); + int wrote = WriteAll(dst_file, file_contents.c_str(), file_size); RecordFileWriteStat(wrote); if (wrote == -1) { - SB_LOG(WARNING) << "SbFileWriteAll failed for file=" << path_to_dst_file; + SB_LOG(WARNING) << "WriteAll failed for file=" << path_to_dst_file; return false; } - SbFileClose(dst_file); + close(dst_file); } closedir(src_dir); @@ -239,8 +238,36 @@ void* ThreadEntryPoint(void* context) { pthread_setname_np(pthread_self(), "StarboardMain"); g_app_created_semaphore = static_cast(context); +#if SB_API_VERSION >= 15 int unused_value = -1; int error_level = SbRunStarboardMain(unused_value, nullptr, SbEventHandle); +#else + ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); + ApplicationAndroid app(looper); + + CommandLine command_line(GetArgs()); + LogInit(command_line); + +#if SB_IS(EVERGREEN_COMPATIBLE) + InstallCrashpadHandler(command_line); +#endif // SB_IS(EVERGREEN_COMPATIBLE) + + // Mark the app running before signaling app created so there's no race to + // allow sending the first AndroidCommand after onCreate() returns. + g_app_running.store(true); + + // Signal GameActivity_onCreate() that it may proceed. + g_app_created_semaphore->Put(); + + // Enter the Starboard run loop until stopped. + int error_level = + app.Run(std::move(command_line), GetStartDeepLink().c_str()); + + // Mark the app not running before informing StarboardBridge that the app is + // stopped so that we won't send any more AndroidCommands as a result of + // shutting down the Activity. + g_app_running.store(false); +#endif // SB_API_VERSION >= 15 // Our launcher.py looks for this to know when the app (test) is done. SB_LOG(INFO) << "***Application Stopped*** " << error_level; @@ -388,6 +415,7 @@ Java_dev_cobalt_coat_VolumeStateReceiver_nativeMuteChanged(JNIEnv* env, } // namespace +#if SB_API_VERSION >= 15 extern "C" int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { @@ -419,6 +447,8 @@ extern "C" int SbRunStarboardMain(int argc, return error_level; } +#endif // SB_API_VERSION >= 15 + } // namespace shared } // namespace android } // namespace starboard diff --git a/starboard/android/shared/android_media_session_client.cc b/starboard/android/shared/android_media_session_client.cc index 35631b616a14..9b5f470a058b 100644 --- a/starboard/android/shared/android_media_session_client.cc +++ b/starboard/android/shared/android_media_session_client.cc @@ -191,7 +191,7 @@ void OnMediaSessionStateChanged( if (artwork_count > 0) { CobaltExtensionMediaImage* artwork(media_metadata->artwork); ScopedLocalJavaRef media_image_class( - env->FindClassExtOrAbort("dev/cobalt/media/MediaImage")); + env->FindClassExtOrAbort("dev/cobalt/coat/MediaImage")); jmethodID media_image_constructor = env->GetMethodID( media_image_class.Get(), "", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"); @@ -234,7 +234,7 @@ void OnMediaSessionStateChanged( env->CallStarboardVoidMethodOrAbort( "updateMediaSession", "(IJJFLjava/lang/String;Ljava/lang/String;Ljava/lang/String;" - "[Ldev/cobalt/media/MediaImage;J)V", + "[Ldev/cobalt/coat/MediaImage;J)V", playback_state, playback_state_actions, session_state.current_playback_position / 1000, static_cast(session_state.actual_playback_rate), j_title.Get(), @@ -290,9 +290,9 @@ const void* GetMediaSessionApi() { } // namespace starboard extern "C" SB_EXPORT_PLATFORM void -Java_dev_cobalt_media_CobaltMediaSession_nativeInvokeAction(JNIEnv* env, - jclass unused_clazz, - jlong action, - jlong seek_ms) { +Java_dev_cobalt_coat_CobaltMediaSession_nativeInvokeAction(JNIEnv* env, + jclass unused_clazz, + jlong action, + jlong seek_ms) { starboard::android::shared::NativeInvokeAction(action, seek_ms); } diff --git a/starboard/android/shared/application_android.cc b/starboard/android/shared/application_android.cc index d040ca4cdb0e..820b339d6f45 100644 --- a/starboard/android/shared/application_android.cc +++ b/starboard/android/shared/application_android.cc @@ -98,9 +98,13 @@ int64_t GetAppStartTimestamp() { // "using" doesn't work with class members, so make a local convenience type. typedef ::starboard::shared::starboard::Application::Event Event; +#if SB_API_VERSION >= 15 ApplicationAndroid::ApplicationAndroid( ALooper* looper, SbEventHandleCallback sb_event_handle_callback) +#else +ApplicationAndroid::ApplicationAndroid(ALooper* looper) +#endif // SB_API_VERSION >= 15 : looper_(looper), native_window_(NULL), android_command_readfd_(-1), @@ -110,7 +114,9 @@ ApplicationAndroid::ApplicationAndroid( android_command_condition_(android_command_mutex_), activity_state_(AndroidCommand::kUndefined), window_(kSbWindowInvalid), +#if SB_API_VERSION >= 15 QueueApplication(sb_event_handle_callback), +#endif // SB_API_VERSION >= 15 last_is_accessibility_high_contrast_text_enabled_(false) { handle_system_events_.store(true); // Initialize Time Zone early so that local time works correctly. diff --git a/starboard/android/shared/application_android.h b/starboard/android/shared/application_android.h index aa372bba92f2..d53b3ef91e67 100644 --- a/starboard/android/shared/application_android.h +++ b/starboard/android/shared/application_android.h @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -26,7 +27,6 @@ #include "starboard/android/shared/input_events_generator.h" #include "starboard/android/shared/jni_env_ext.h" #include "starboard/atomic.h" -#include "starboard/common/atomic.h" #include "starboard/common/condition_variable.h" #include "starboard/common/mutex.h" #include "starboard/configuration.h" @@ -61,8 +61,12 @@ class ApplicationAndroid void* data = nullptr; }; +#if SB_API_VERSION >= 15 ApplicationAndroid(ALooper* looper, SbEventHandleCallback sb_event_handle_callback); +#else + explicit ApplicationAndroid(ALooper* looper); +#endif // SB_API_VERSION >= 15 ~ApplicationAndroid() override; static ApplicationAndroid* Get() { @@ -129,7 +133,7 @@ class ApplicationAndroid // In certain situations, the Starboard thread should not try to process new // system events (e.g. while one is being processed). - atomic_bool handle_system_events_; + std::atomic_bool handle_system_events_{false}; // Synchronization for commands that change availability of Android resources // such as the input and/or native_window_. @@ -141,7 +145,7 @@ class ApplicationAndroid SbAtomic32 android_stop_count_ = 0; // Set to true in the destructor to ensure other threads stop waiting. - atomic_bool application_destroying_; + std::atomic_bool application_destroying_{false}; // The last Activity lifecycle state command received. AndroidCommand::CommandType activity_state_; diff --git a/starboard/android/shared/asset_manager.cc b/starboard/android/shared/asset_manager.cc index a386544390db..201b956e7ba6 100644 --- a/starboard/android/shared/asset_manager.cc +++ b/starboard/android/shared/asset_manager.cc @@ -15,6 +15,7 @@ #include "starboard/android/shared/asset_manager.h" #include +#include #include #include #include @@ -33,6 +34,44 @@ namespace starboard { namespace android { namespace shared { +namespace { + +// Returns the fallback for the given asset path, or an empty string if none. +// NOTE: While Cobalt now provides a mechanism for loading system fonts through +// SbSystemGetPath(), using the fallback logic within SbFileOpen() is +// still preferred for Android's fonts. The reason for this is that the +// Android OS actually allows fonts to be loaded from two locations: one +// that it provides; and one that the devices running its OS, which it +// calls vendors, can provide. Rather than including the full Android font +// package, vendors have the option of using a smaller Android font +// package and supplementing it with their own fonts. +// +// If Android were to use SbSystemGetPath() for its fonts, vendors would +// have no way of providing those supplemental fonts to Cobalt, which +// could result in a limited selection of fonts being available. By +// treating Android's fonts as Cobalt's fonts, Cobalt can still offer a +// straightforward mechanism for including vendor fonts via +// SbSystemGetPath(). +std::string FallbackPath(const std::string& path) { + // We don't package most font files in Cobalt content and fallback to the + // system font file of the same name. + const std::string fonts_xml("fonts.xml"); + const std::string system_fonts_dir("/system/fonts/"); + const std::string cobalt_fonts_dir("/cobalt/assets/fonts/"); + + // Fonts fallback to the system fonts. + if (path.compare(0, cobalt_fonts_dir.length(), cobalt_fonts_dir) == 0) { + std::string file_name = path.substr(cobalt_fonts_dir.length()); + // fonts.xml doesn't fallback. + if (file_name != fonts_xml) { + return system_fonts_dir + file_name; + } + } + return std::string(); +} + +} // namespace + // static SB_ONCE_INITIALIZE_FUNCTION(AssetManager, AssetManager::GetInstance); @@ -60,13 +99,17 @@ std::string AssetManager::TempFilepath(uint64_t internal_fd) const { return tmp_root_ + "/" + std::to_string(internal_fd); } -int AssetManager::Open(const char* path) { +int AssetManager::Open(const char* path, int oflag) { if (!path) { return -1; } AAsset* asset = OpenAndroidAsset(path); if (!asset) { + std::string fallback_path = FallbackPath(path); + if (!fallback_path.empty()) { + return open(fallback_path.c_str(), oflag); + } SB_LOG(WARNING) << "Asset path not found within package: " << path; return -1; } diff --git a/starboard/android/shared/asset_manager.h b/starboard/android/shared/asset_manager.h index 10f1a8b5d526..8be4cf8fe90d 100644 --- a/starboard/android/shared/asset_manager.h +++ b/starboard/android/shared/asset_manager.h @@ -29,7 +29,7 @@ namespace shared { class AssetManager { public: static AssetManager* GetInstance(); - int Open(const char* path); + int Open(const char* path, int oflag); int Close(int fd); bool IsAssetFd(int fd) const; diff --git a/starboard/android/shared/audio_renderer_passthrough.h b/starboard/android/shared/audio_renderer_passthrough.h index a8b25974b55d..7e1901bc1171 100644 --- a/starboard/android/shared/audio_renderer_passthrough.h +++ b/starboard/android/shared/audio_renderer_passthrough.h @@ -116,9 +116,9 @@ class AudioRendererPassthrough EndedCB ended_cb_; int frames_per_input_buffer_ = 0; // Set once before all uses. - atomic_bool can_accept_more_data_{true}; - atomic_bool prerolled_; - atomic_bool end_of_stream_played_; + std::atomic_bool can_accept_more_data_{true}; + std::atomic_bool prerolled_{false}; + std::atomic_bool end_of_stream_played_{false}; bool end_of_stream_written_ = false; // Only accessed on PlayerWorker thread. diff --git a/starboard/android/shared/audio_track_audio_sink_type.cc b/starboard/android/shared/audio_track_audio_sink_type.cc index 4af3a1751f18..3a92470983b8 100644 --- a/starboard/android/shared/audio_track_audio_sink_type.cc +++ b/starboard/android/shared/audio_track_audio_sink_type.cc @@ -74,6 +74,7 @@ int GetMaxFramesPerRequestForTunnelMode(int sampling_frequency_hz) { } bool HasRemoteAudioOutput() { +#if SB_API_VERSION >= 15 // SbPlayerBridge::GetAudioConfigurations() reads up to 32 configurations. The // limit here is to avoid infinite loop and also match // SbPlayerBridge::GetAudioConfigurations(). @@ -100,6 +101,8 @@ bool HasRemoteAudioOutput() { index++; } return false; +#endif // SB_API_VERSION >= 15 + return false; } } // namespace diff --git a/starboard/android/shared/drm_system.cc b/starboard/android/shared/drm_system.cc index 7897d3b95f78..156155566bf7 100644 --- a/starboard/android/shared/drm_system.cc +++ b/starboard/android/shared/drm_system.cc @@ -20,7 +20,6 @@ #include "starboard/android/shared/jni_env_ext.h" #include "starboard/android/shared/jni_utils.h" #include "starboard/android/shared/media_common.h" -#include "starboard/common/atomic.h" #include "starboard/common/instance_counter.h" #include "starboard/common/thread.h" diff --git a/starboard/android/shared/drm_system.h b/starboard/android/shared/drm_system.h index 56065a47c39f..2ff029f80d4b 100644 --- a/starboard/android/shared/drm_system.h +++ b/starboard/android/shared/drm_system.h @@ -20,13 +20,13 @@ #include #include +#include #include #include #include #include "starboard/android/shared/jni_utils.h" #include "starboard/android/shared/media_common.h" -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/thread.h" @@ -128,7 +128,7 @@ class DrmSystem : public ::SbDrmSystemPrivate, private Thread { Mutex mutex_; std::unordered_map> cached_drm_key_ids_; bool hdcp_lost_; - atomic_bool created_media_crypto_session_; + std::atomic_bool created_media_crypto_session_{false}; std::vector metrics_; }; diff --git a/starboard/android/shared/egl_swap_buffers.cc b/starboard/android/shared/egl_swap_buffers.cc index 8cc824127f3b..6c36a5604577 100644 --- a/starboard/android/shared/egl_swap_buffers.cc +++ b/starboard/android/shared/egl_swap_buffers.cc @@ -15,14 +15,15 @@ #include #include +#include + #include "starboard/android/shared/video_window.h" -#include "starboard/common/atomic.h" #include "starboard/shared/gles/gl_call.h" namespace starboard { namespace android { namespace shared { -extern atomic_bool g_block_swapbuffers; +extern std::atomic_bool g_block_swapbuffers; } // namespace shared } // namespace android } // namespace starboard diff --git a/starboard/android/shared/file_can_open.cc b/starboard/android/shared/file_can_open.cc index 0669ab5f322b..3849cf96cb5a 100644 --- a/starboard/android/shared/file_can_open.cc +++ b/starboard/android/shared/file_can_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -42,3 +44,5 @@ bool SbFileCanOpen(const char* path, int flags) { return result; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_close.cc b/starboard/android/shared/file_close.cc index 192aedec0f4f..b44eeca4ae62 100644 --- a/starboard/android/shared/file_close.cc +++ b/starboard/android/shared/file_close.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -28,3 +30,5 @@ bool SbFileClose(SbFile file) { return ::starboard::shared::posix::impl::FileClose(file); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_delete.cc b/starboard/android/shared/file_delete.cc index 9a0ab8b2c8ed..477b6ecc4bf0 100644 --- a/starboard/android/shared/file_delete.cc +++ b/starboard/android/shared/file_delete.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/android/shared/file_internal.h" @@ -20,3 +22,5 @@ bool SbFileDelete(const char* path) { return ::starboard::shared::posix::impl::FileDelete(path); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_exists.cc b/starboard/android/shared/file_exists.cc index 32dbd3afc5a8..810315828180 100644 --- a/starboard/android/shared/file_exists.cc +++ b/starboard/android/shared/file_exists.cc @@ -13,9 +13,11 @@ // limitations under the License. #if SB_API_VERSION < 16 + #include "starboard/file.h" bool SbFileExists(const char* path) { return SbFileCanOpen(path, kSbFileRead); } -#endif + +#endif // SB_API_VERSION < 16 diff --git a/starboard/android/shared/file_flush.cc b/starboard/android/shared/file_flush.cc index 25634ca4402b..7ab036bb0f5c 100644 --- a/starboard/android/shared/file_flush.cc +++ b/starboard/android/shared/file_flush.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/android/shared/file_internal.h" @@ -20,3 +22,5 @@ bool SbFileFlush(SbFile file) { return ::starboard::shared::posix::impl::FileFlush(file); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_get_info.cc b/starboard/android/shared/file_get_info.cc index d7e755952cfc..c7979fbee19a 100644 --- a/starboard/android/shared/file_get_info.cc +++ b/starboard/android/shared/file_get_info.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -32,3 +34,5 @@ bool SbFileGetInfo(SbFile file, SbFileInfo* out_info) { return ::starboard::shared::posix::impl::FileGetInfo(file, out_info); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_open.cc b/starboard/android/shared/file_open.cc index 8d82ab584359..8102b58f32d8 100644 --- a/starboard/android/shared/file_open.cc +++ b/starboard/android/shared/file_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -104,3 +106,5 @@ SbFile SbFileOpen(const char* path, } return kSbFileInvalid; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_read.cc b/starboard/android/shared/file_read.cc index d283019f9813..2d90d4f8d5b3 100644 --- a/starboard/android/shared/file_read.cc +++ b/starboard/android/shared/file_read.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -30,3 +32,5 @@ int SbFileRead(SbFile file, char* data, int size) { return ::starboard::shared::posix::impl::FileRead(file, data, size); } } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_seek.cc b/starboard/android/shared/file_seek.cc index 590446b92e92..e64f7fc5b6e9 100644 --- a/starboard/android/shared/file_seek.cc +++ b/starboard/android/shared/file_seek.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -26,3 +28,5 @@ int64_t SbFileSeek(SbFile file, SbFileWhence whence, int64_t offset) { return ::starboard::shared::posix::impl::FileSeek(file, whence, offset); } } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_truncate.cc b/starboard/android/shared/file_truncate.cc index c1075e789323..fe96b632a924 100644 --- a/starboard/android/shared/file_truncate.cc +++ b/starboard/android/shared/file_truncate.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/android/shared/file_internal.h" @@ -20,3 +22,5 @@ bool SbFileTruncate(SbFile file, int64_t length) { return ::starboard::shared::posix::impl::FileTruncate(file, length); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/file_write.cc b/starboard/android/shared/file_write.cc index 77054354de06..e6c99cb85515 100644 --- a/starboard/android/shared/file_write.cc +++ b/starboard/android/shared/file_write.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/android/shared/file_internal.h" @@ -20,3 +22,5 @@ int SbFileWrite(SbFile file, const char* data, int size) { return ::starboard::shared::posix::impl::FileWrite(file, data, size); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/android/shared/input_events_generator.cc b/starboard/android/shared/input_events_generator.cc index be0ec9334262..aed501be42c6 100644 --- a/starboard/android/shared/input_events_generator.cc +++ b/starboard/android/shared/input_events_generator.cc @@ -232,8 +232,10 @@ SbKey AInputEventToSbKey(GameActivityKeyEvent* event) { return kSbKeyMediaRewind; case AKEYCODE_MEDIA_FAST_FORWARD: return kSbKeyMediaFastForward; +#if SB_API_VERSION >= 15 case AKEYCODE_MEDIA_RECORD: return kSbKeyRecord; +#endif // TV Remote specific case AKEYCODE_CHANNEL_UP: diff --git a/starboard/android/shared/media_capabilities_cache.cc b/starboard/android/shared/media_capabilities_cache.cc index 10e2d1998d84..19d5c71d7111 100644 --- a/starboard/android/shared/media_capabilities_cache.cc +++ b/starboard/android/shared/media_capabilities_cache.cc @@ -74,6 +74,7 @@ constexpr int TYPE_USB_HEADSET = 22; constexpr int TYPE_WIRED_HEADPHONES = 4; constexpr int TYPE_WIRED_HEADSET = 3; +#if SB_API_VERSION >= 15 SbMediaAudioConnector GetConnectorFromAndroidOutputType( int android_output_device_type) { switch (android_output_device_type) { @@ -145,6 +146,7 @@ SbMediaAudioConnector GetConnectorFromAndroidOutputType( << android_output_device_type; return kSbMediaAudioConnectorUnknown; } +#endif // SB_API_VERSION >= 15 bool EndsWith(const std::string& str, const std::string& suffix) { if (str.size() < suffix.size()) { @@ -267,8 +269,12 @@ bool GetAudioConfiguration(int index, return env->CallIntMethodOrAbort(j_output_device_info.Get(), name, "()I"); }; +#if SB_API_VERSION >= 15 configuration->connector = GetConnectorFromAndroidOutputType(call_int_method("getType")); +#else // SB_API_VERSION >= 15 + configuration->connector = kSbMediaAudioConnectorHdmi; +#endif // SB_API_VERSION >= 15 configuration->latency = 0; configuration->coding_type = kSbMediaAudioCodingTypePcm; configuration->number_of_channels = call_int_method("getChannels"); diff --git a/starboard/android/shared/media_codec_bridge_eradicator.h b/starboard/android/shared/media_codec_bridge_eradicator.h index 5681dd9046b5..19fd776a9d6f 100644 --- a/starboard/android/shared/media_codec_bridge_eradicator.h +++ b/starboard/android/shared/media_codec_bridge_eradicator.h @@ -16,10 +16,10 @@ #define STARBOARD_ANDROID_SHARED_MEDIA_CODEC_BRIDGE_ERADICATOR_H_ #include +#include #include #include "starboard/android/shared/jni_env_ext.h" -#include "starboard/common/atomic.h" #include "starboard/common/condition_variable.h" #include "starboard/common/mutex.h" @@ -52,7 +52,7 @@ class MediaCodecBridgeEradicator { private: static void* DestroyMediaCodecBridge(void* context); - atomic_bool is_enabled_{false}; + std::atomic_bool is_enabled_{false}; // Maximum wait time when creating a new MediaCodecBridge if the background // cleanup thread (MediaCodecBridgeEradicator::DestroyMediaCodecBridge) is // unresponsive. diff --git a/starboard/android/shared/media_decoder.cc b/starboard/android/shared/media_decoder.cc index c2f36735bb38..e1ea3dc1bd87 100644 --- a/starboard/android/shared/media_decoder.cc +++ b/starboard/android/shared/media_decoder.cc @@ -102,7 +102,7 @@ MediaDecoder::MediaDecoder(Host* host, if (audio_stream_info.codec != kSbMediaAudioCodecOpus && !audio_stream_info.audio_specific_config.empty()) { pending_tasks_.push_back(Event(audio_stream_info.audio_specific_config)); - number_of_pending_tasks_.increment(); + ++number_of_pending_tasks_; } } @@ -207,7 +207,7 @@ void MediaDecoder::WriteInputBuffers(const InputBuffers& input_buffers) { bool need_signal = pending_tasks_.empty(); for (const auto& input_buffer : input_buffers) { pending_tasks_.push_back(Event(input_buffer)); - number_of_pending_tasks_.increment(); + ++number_of_pending_tasks_; } if (need_signal) { condition_variable_.Signal(); @@ -220,7 +220,7 @@ void MediaDecoder::WriteEndOfStream() { stream_ended_.store(true); ScopedLock scoped_lock(mutex_); pending_tasks_.push_back(Event(Event::kWriteEndOfStream)); - number_of_pending_tasks_.increment(); + ++number_of_pending_tasks_; if (pending_tasks_.size() == 1) { condition_variable_.Signal(); } @@ -431,7 +431,7 @@ bool MediaDecoder::ProcessOneInputBuffer( input_buffer_indices->erase(input_buffer_indices->begin()); event = pending_tasks->front(); pending_tasks->pop_front(); - number_of_pending_tasks_.decrement(); + --number_of_pending_tasks_; } SB_DCHECK(event.type == Event::kWriteCodecConfig || diff --git a/starboard/android/shared/media_decoder.h b/starboard/android/shared/media_decoder.h index 1805966b3c92..abd99b5e4ac3 100644 --- a/starboard/android/shared/media_decoder.h +++ b/starboard/android/shared/media_decoder.h @@ -17,6 +17,7 @@ #include +#include #include #include #include @@ -24,7 +25,6 @@ #include "starboard/android/shared/drm_system.h" #include "starboard/android/shared/media_codec_bridge.h" -#include "starboard/common/atomic.h" #include "starboard/common/condition_variable.h" #include "starboard/common/mutex.h" #include "starboard/common/optional.h" @@ -188,13 +188,13 @@ class MediaDecoder final SbPlayerError error_; std::string error_message_; - atomic_bool stream_ended_; + std::atomic_bool stream_ended_{false}; - atomic_bool destroying_; + std::atomic_bool destroying_{false}; optional pending_queue_input_buffer_task_; - atomic_int32_t number_of_pending_tasks_; + std::atomic number_of_pending_tasks_{0}; Mutex mutex_; ConditionVariable condition_variable_; diff --git a/starboard/android/shared/player_components_factory.h b/starboard/android/shared/player_components_factory.h index d6060d8406e4..0b8f6cb0cd2f 100644 --- a/starboard/android/shared/player_components_factory.h +++ b/starboard/android/shared/player_components_factory.h @@ -15,6 +15,7 @@ #ifndef STARBOARD_ANDROID_SHARED_PLAYER_COMPONENTS_FACTORY_H_ #define STARBOARD_ANDROID_SHARED_PLAYER_COMPONENTS_FACTORY_H_ +#include #include #include #include @@ -150,7 +151,7 @@ class AudioRendererSinkCallbackStub error_occurred_.store(true); } - atomic_bool error_occurred_; + std::atomic_bool error_occurred_{false}; }; class PlayerComponentsPassthrough diff --git a/starboard/android/shared/player_create.cc b/starboard/android/shared/player_create.cc index bcd827a675dd..78b4ba46f252 100644 --- a/starboard/android/shared/player_create.cc +++ b/starboard/android/shared/player_create.cc @@ -53,10 +53,17 @@ SbPlayer SbPlayerCreate(SbWindow window, return kSbPlayerInvalid; } +#if SB_API_VERSION >= 15 const SbMediaAudioStreamInfo& audio_stream_info = creation_param->audio_stream_info; const SbMediaVideoStreamInfo& video_stream_info = creation_param->video_stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaAudioSampleInfo& audio_stream_info = + creation_param->audio_sample_info; + const SbMediaVideoSampleInfo& video_stream_info = + creation_param->video_sample_info; +#endif // SB_API_VERSION >= 15 bool has_audio = audio_stream_info.codec != kSbMediaAudioCodecNone; bool has_video = video_stream_info.codec != kSbMediaVideoCodecNone; diff --git a/starboard/android/shared/player_get_preferred_output_mode.cc b/starboard/android/shared/player_get_preferred_output_mode.cc index f32d63712881..185f8e1bd3dd 100644 --- a/starboard/android/shared/player_get_preferred_output_mode.cc +++ b/starboard/android/shared/player_get_preferred_output_mode.cc @@ -30,10 +30,17 @@ SbPlayerOutputMode SbPlayerGetPreferredOutputMode( return kSbPlayerOutputModeInvalid; } +#if SB_API_VERSION >= 15 const SbMediaAudioStreamInfo& audio_stream_info = creation_param->audio_stream_info; const SbMediaVideoStreamInfo& video_stream_info = creation_param->video_stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaAudioSampleInfo& audio_stream_info = + creation_param->audio_sample_info; + const SbMediaVideoSampleInfo& video_stream_info = + creation_param->video_sample_info; +#endif // SB_API_VERSION >= 15 if (audio_stream_info.codec != kSbMediaAudioCodecNone && !audio_stream_info.mime) { diff --git a/starboard/android/shared/posix_emu/file.cc b/starboard/android/shared/posix_emu/file.cc index d18ebefb3997..6f876e5856d9 100644 --- a/starboard/android/shared/posix_emu/file.cc +++ b/starboard/android/shared/posix_emu/file.cc @@ -55,7 +55,7 @@ int __wrap_open(const char* path, int oflag, ...) { return __real_open(path, oflag); } } - return AssetManager::GetInstance()->Open(path); + return AssetManager::GetInstance()->Open(path, oflag); } } // extern "C" diff --git a/starboard/android/shared/posix_emu/stat.cc b/starboard/android/shared/posix_emu/stat.cc index 5f7864c6ab33..572fca2f2dbc 100644 --- a/starboard/android/shared/posix_emu/stat.cc +++ b/starboard/android/shared/posix_emu/stat.cc @@ -12,12 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include +#include #include #include "starboard/android/shared/directory_internal.h" #include "starboard/android/shared/file_internal.h" +#include "starboard/common/log.h" #include "starboard/directory.h" using starboard::android::shared::IsAndroidAssetPath; @@ -41,20 +44,6 @@ static SB_C_FORCE_INLINE time_t WindowsUsecToTimeTAndroid(int64_t time) { return posix_time; } -static void MapSbFileInfoToStat(SbFileInfo* file_info, struct stat* stat_info) { - stat_info->st_mode = 0; - if (file_info->is_directory) { - stat_info->st_mode = S_IFDIR; - } else if (file_info->is_symbolic_link) { - stat_info->st_mode = S_IFLNK; - } - - stat_info->st_ctime = WindowsUsecToTimeTAndroid(file_info->creation_time); - stat_info->st_atime = WindowsUsecToTimeTAndroid(file_info->last_accessed); - stat_info->st_mtime = WindowsUsecToTimeTAndroid(file_info->last_modified); - stat_info->st_size = file_info->size; -} - // This needs to be exported to ensure shared_library targets include it. int __wrap_stat(const char* path, struct stat* info) { // SbFileExists(path) implementation for Android @@ -62,13 +51,11 @@ int __wrap_stat(const char* path, struct stat* info) { return __real_stat(path, info); // Using system level stat call } - SbFile file = SbFileOpen(path, kSbFileRead | kSbFileOpenOnly, NULL, NULL); - SbFileInfo out_info; - if (file) { - bool result = SbFileGetInfo(file, &out_info); - MapSbFileInfoToStat(&out_info, info); - SbFileClose(file); - return 0; + int file = open(path, O_RDONLY, S_IRUSR | S_IWUSR); + if (file >= 0) { + int result = fstat(file, info); + close(file); + return result; } // Values from SbFileGetPathInfo diff --git a/starboard/android/shared/system_get_device_type.cc b/starboard/android/shared/system_get_device_type.cc new file mode 100644 index 000000000000..8c7eb3c0abb8 --- /dev/null +++ b/starboard/android/shared/system_get_device_type.cc @@ -0,0 +1,23 @@ +// Copyright 2016 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + return kSbSystemDeviceTypeAndroidTV; +} + +#endif diff --git a/starboard/android/shared/system_get_property.cc b/starboard/android/shared/system_get_property.cc index 8cf1ccd57df0..3f14106b8362 100644 --- a/starboard/android/shared/system_get_property.cc +++ b/starboard/android/shared/system_get_property.cc @@ -161,9 +161,11 @@ bool SbSystemGetProperty(SbSystemPropertyId property_id, return CopyStringAndTestIfSuccess(out_value, value_length, limit_ad_tracking_enabled ? "1" : "0"); } +#if SB_API_VERSION >= 15 case kSbSystemPropertyDeviceType: return CopyStringAndTestIfSuccess(out_value, value_length, starboard::kSystemDeviceTypeAndroidTV); +#endif default: SB_DLOG(WARNING) << __FUNCTION__ << ": Unrecognized property: " << property_id; diff --git a/starboard/android/shared/video_decoder.h b/starboard/android/shared/video_decoder.h index 5241bbb1f9fe..72f941fcc562 100644 --- a/starboard/android/shared/video_decoder.h +++ b/starboard/android/shared/video_decoder.h @@ -166,8 +166,8 @@ class VideoDecoder std::unique_ptr video_frame_tracker_; // Preroll in tunnel mode is handled in this class instead of in the renderer. - atomic_bool tunnel_mode_prerolling_{true}; - atomic_bool tunnel_mode_frame_rendered_; + std::atomic_bool tunnel_mode_prerolling_{true}; + std::atomic_bool tunnel_mode_frame_rendered_{false}; // If decode-to-texture is enabled, then we store the decode target texture // inside of this |decode_target_| member. @@ -193,14 +193,14 @@ class VideoDecoder std::unique_ptr media_decoder_; - atomic_int32_t number_of_frames_being_decoded_; + std::atomic number_of_frames_being_decoded_{0}; scoped_refptr sink_; int input_buffer_written_ = 0; bool first_texture_received_ = false; bool end_of_stream_written_ = false; volatile int64_t first_buffer_timestamp_; // microseconds - atomic_bool has_new_texture_available_; + std::atomic_bool has_new_texture_available_{false}; // Use |owns_video_surface_| only on decoder thread, to avoid unnecessary // invocation of ReleaseVideoSurface(), though ReleaseVideoSurface() would diff --git a/starboard/common/BUILD.gn b/starboard/common/BUILD.gn index bbf938f8173b..efe6da76e6fe 100644 --- a/starboard/common/BUILD.gn +++ b/starboard/common/BUILD.gn @@ -94,6 +94,14 @@ static_library("common") { ] } +static_library("file_wrapper") { + check_includes = false + sources = [ + "file_wrapper.cc", + "file_wrapper.h", + ] +} + target(gtest_target_type, "common_test") { testonly = true sources = [ diff --git a/starboard/common/condition_variable.cc b/starboard/common/condition_variable.cc index d0b253b995df..9cc6604a5887 100644 --- a/starboard/common/condition_variable.cc +++ b/starboard/common/condition_variable.cc @@ -66,6 +66,9 @@ bool ConditionVariable::WaitTimed(int64_t duration) const { bool was_signaled = SbConditionVariableIsSignaled( SbConditionVariableWaitTimed(&condition_, mutex_->mutex(), duration)); #else + if (duration < 0) { + duration = 0; + } #if !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) int64_t timeout_time_usec = starboard::CurrentMonotonicTime(); #else @@ -73,6 +76,14 @@ bool ConditionVariable::WaitTimed(int64_t duration) const { #endif // !SB_HAS_QUIRK(NO_CONDATTR_SETCLOCK_SUPPORT) timeout_time_usec += duration; + // Detect overflow if timeout is near kSbInt64Max. Since timeout can't be + // negative at this point, if it goes negative after adding now, we know we've + // gone over. Especially posix now, which has a 400 year advantage over + // Chromium (Windows) now. + if (timeout_time_usec < 0) { + timeout_time_usec = kSbInt64Max; + } + struct timespec timeout; timeout.tv_sec = timeout_time_usec / 1000'000; timeout.tv_nsec = (timeout_time_usec % 1000'000) * 1000; diff --git a/starboard/common/file.cc b/starboard/common/file.cc index 99cb273f9b02..4e5b30608c52 100644 --- a/starboard/common/file.cc +++ b/starboard/common/file.cc @@ -29,6 +29,7 @@ #include "starboard/configuration_constants.h" #include "starboard/directory.h" #include "starboard/file.h" +#include "starboard/shared/starboard/file_atomic_replace_write_file.h" #include "starboard/string.h" namespace starboard { @@ -44,6 +45,34 @@ bool DirectoryCloseLogFailure(const char* path, DIR* dir) { } // namespace +bool FileCanOpen(const char* path, int flags) { + struct stat file_info; + if (stat(path, &file_info) != 0) { + return false; + } + + bool has_read_flag = (flags & O_RDONLY) || (flags & O_RDWR); + bool has_write_flag = (flags & O_WRONLY) || (flags & O_RDWR); + bool can_read = file_info.st_mode & S_IRUSR; + bool can_write = file_info.st_mode & S_IWUSR; + + if (has_read_flag && !can_read) { + errno = EACCES; + return false; + } + + if (has_write_flag && !can_write) { + errno = EACCES; + return false; + } + + return true; +} + +bool IsValid(int file) { + return file >= 0; +} + ssize_t ReadAll(int fd, void* data, int size) { if (fd < 0 || size < 0) { return -1; @@ -85,11 +114,9 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root) { // The |path| points to a file. Remove it and return. if (!dir) { - return SbFileDelete(path); + return (unlink(path) == 0); } - SbFileInfo info; - std::vector entry(kSbFileMaxName); struct dirent dirent_buffer; @@ -120,7 +147,7 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root) { // Don't forget to close and remove the directory before returning! if (DirectoryCloseLogFailure(path, dir)) { - return preserve_root ? true : SbFileDelete(path); + return preserve_root ? true : (rmdir(path) == 0); } return false; } diff --git a/starboard/common/file.h b/starboard/common/file.h index 15b8f4227850..b599894c89ed 100644 --- a/starboard/common/file.h +++ b/starboard/common/file.h @@ -20,8 +20,6 @@ #ifndef STARBOARD_COMMON_FILE_H_ #define STARBOARD_COMMON_FILE_H_ -#include "starboard/file.h" - #include #include #include @@ -38,6 +36,10 @@ namespace starboard { +bool FileCanOpen(const char* path, int flags); + +bool IsValid(int file); + ssize_t ReadAll(int fd, void* data, int size); void RecordFileWriteStat(int write_file_result); @@ -56,9 +58,9 @@ bool SbFileDeleteRecursive(const char* path, bool preserve_root); ssize_t WriteAll(int fd, const void* data, int size); -// A class that opens an SbFile in its constructor and closes it in its +// A class that opens an file descriptor in its constructor and closes it in its // destructor, so the file is open for the lifetime of the object. Member -// functions call the corresponding SbFile function. +// functions call the corresponding file function. class ScopedFile { public: ScopedFile(const char* path, int flags, int mode) : file_(-1) { @@ -77,10 +79,10 @@ class ScopedFile { int file() const { return file_; } - bool IsValid() const { return file_ >= 0; } + bool IsValid() const { return starboard::IsValid(file_); } - int64_t Seek(SbFileWhence whence, int64_t offset) const { - return lseek(file_, static_cast(offset), static_cast(whence)); + int64_t Seek(int64_t offset, int whence) const { + return lseek(file_, static_cast(offset), whence); } int Read(char* data, int size) const { return read(file_, data, size); } diff --git a/starboard/common/file_wrapper.cc b/starboard/common/file_wrapper.cc new file mode 100644 index 000000000000..12d38064f1ae --- /dev/null +++ b/starboard/common/file_wrapper.cc @@ -0,0 +1,99 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/common/file_wrapper.h" + +#include +#include + +#include "starboard/common/file.h" +#include "starboard/common/log.h" +#include "starboard/common/string.h" + +namespace { + +bool IsUpdate(const char* mode) { + for (const char* m = mode; *m != '\0'; ++m) { + if (*m == '+') { + return true; + } + } + + return false; +} +} // namespace + +extern "C" { + +int FileModeStringToFlags(const char* mode) { + if (!mode) { + return 0; + } + + int length = static_cast(strlen(mode)); + if (length < 1) { + return 0; + } + + int flags = 0; + switch (mode[0]) { + case 'r': + if (IsUpdate(mode + 1)) { + flags |= O_RDWR; + } else { + flags |= O_RDONLY; + } + break; + case 'w': + if (IsUpdate(mode + 1)) { + flags |= O_RDWR; + } else { + flags |= O_WRONLY; + } + flags |= O_CREAT | O_TRUNC; + break; + case 'a': + if (IsUpdate(mode + 1)) { + flags |= O_RDWR; + } else { + flags |= O_WRONLY; + } + flags |= O_CREAT; + break; + default: + SB_NOTREACHED(); + break; + } + return flags; +} + +int file_close(FilePtr file) { + if (!file) { + return -1; + } + int result = -1; + if (file->fd >= 0) { + result = close(file->fd); + } + delete file; + return result; +} + +FilePtr file_open(const char* path, int mode) { + FilePtr file = new FileStruct(); + file->fd = open(path, mode, S_IRUSR | S_IWUSR); + return file; +} + +} // extern "C" diff --git a/starboard/common/file_wrapper.h b/starboard/common/file_wrapper.h new file mode 100644 index 000000000000..03be8198b69e --- /dev/null +++ b/starboard/common/file_wrapper.h @@ -0,0 +1,44 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef STARBOARD_COMMON_FILE_WRAPPER_H_ +#define STARBOARD_COMMON_FILE_WRAPPER_H_ + +typedef struct FileStruct { + int fd; +} FileStruct; + +typedef FileStruct* FilePtr; + +#ifdef __cplusplus +extern "C" { +#endif + +// Converts an ISO |fopen()| mode string into flags that can be equivalently +// passed into POSIX open(). +// +// |mode|: The mode string to be converted into flags. +int FileModeStringToFlags(const char* mode); + +// Wrapper for close() that takes in a FilePtr instead of a file descriptor. +int file_close(FilePtr file); + +// Wrapper for open() that returns a FilePtr instead of a file descriptor. +FilePtr file_open(const char* path, int mode); + +#ifdef __cplusplus +} +#endif + +#endif // STARBOARD_COMMON_FILE_WRAPPER_H_ diff --git a/starboard/common/media.cc b/starboard/common/media.cc index d1a7294634f1..a7ee8d724c38 100644 --- a/starboard/common/media.cc +++ b/starboard/common/media.cc @@ -597,8 +597,10 @@ const char* GetMediaAudioCodecName(SbMediaAudioCodec codec) { return "flac"; case kSbMediaAudioCodecPcm: return "pcm"; +#if SB_API_VERSION >= 15 case kSbMediaAudioCodecIamf: return "iamf"; +#endif // SB_API_VERSION >= 15 } SB_NOTREACHED(); return "invalid"; @@ -631,22 +633,34 @@ const char* GetMediaVideoCodecName(SbMediaVideoCodec codec) { const char* GetMediaAudioConnectorName(SbMediaAudioConnector connector) { switch (connector) { +#if SB_API_VERSION >= 15 case kSbMediaAudioConnectorUnknown: return "unknown"; +#else // SB_API_VERSION >= 15 + case kSbMediaAudioConnectorNone: + return "none"; +#endif // SB_API_VERSION >= 15 case kSbMediaAudioConnectorAnalog: return "analog"; case kSbMediaAudioConnectorBluetooth: return "bluetooth"; +#if SB_API_VERSION >= 15 case kSbMediaAudioConnectorBuiltIn: return "builtin"; +#endif // SB_API_VERSION >= 15 case kSbMediaAudioConnectorHdmi: return "hdmi"; +#if SB_API_VERSION >= 15 case kSbMediaAudioConnectorRemoteWired: return "remote-wired"; case kSbMediaAudioConnectorRemoteWireless: return "remote-wireless"; case kSbMediaAudioConnectorRemoteOther: return "remote-other"; +#else // SB_API_VERSION >= 15 + case kSbMediaAudioConnectorNetwork: + return "network"; +#endif // SB_API_VERSION >= 15 case kSbMediaAudioConnectorSpdif: return "spdif"; case kSbMediaAudioConnectorUsb: @@ -921,7 +935,11 @@ std::ostream& operator<<(std::ostream& os, const SbMediaVideoSampleInfo& sample_info) { using starboard::GetMediaVideoCodecName; +#if SB_API_VERSION >= 15 const SbMediaVideoStreamInfo& stream_info = sample_info.stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaVideoSampleInfo& stream_info = sample_info; +#endif // SB_API_VERSION >= 15 if (stream_info.codec == kSbMediaVideoCodecNone) { return os; @@ -949,7 +967,11 @@ std::ostream& operator<<(std::ostream& os, using starboard::GetMediaAudioCodecName; using starboard::HexEncode; +#if SB_API_VERSION >= 15 const SbMediaAudioStreamInfo& stream_info = sample_info.stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaAudioSampleInfo& stream_info = sample_info; +#endif // SB_API_VERSION >= 15 if (stream_info.codec == kSbMediaAudioCodecNone) { return os; @@ -971,6 +993,7 @@ std::ostream& operator<<(std::ostream& os, return os; } +#if SB_API_VERSION >= 15 std::ostream& operator<<(std::ostream& os, const SbMediaVideoStreamInfo& stream_info) { using starboard::GetMediaVideoCodecName; @@ -1016,3 +1039,5 @@ std::ostream& operator<<(std::ostream& os, return os; } + +#endif // SB_API_VERSION >= 15 diff --git a/starboard/common/media.h b/starboard/common/media.h index 74b2fb59753b..25fa8283eda3 100644 --- a/starboard/common/media.h +++ b/starboard/common/media.h @@ -65,9 +65,11 @@ std::ostream& operator<<(std::ostream& os, std::ostream& operator<<(std::ostream& os, const SbMediaAudioSampleInfo& sample_info); +#if SB_API_VERSION >= 15 std::ostream& operator<<(std::ostream& os, const SbMediaVideoStreamInfo& stream_info); std::ostream& operator<<(std::ostream& os, const SbMediaAudioStreamInfo& stream_info); +#endif // SB_API_VERSION >= 15 #endif // STARBOARD_COMMON_MEDIA_H_ diff --git a/starboard/common/thread.cc b/starboard/common/thread.cc index 95a15c7a13a6..bdda549b4f9e 100644 --- a/starboard/common/thread.cc +++ b/starboard/common/thread.cc @@ -18,8 +18,8 @@ #include #include +#include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/optional.h" @@ -30,8 +30,8 @@ namespace starboard { struct Thread::Data { std::string name_; pthread_t thread_ = 0; - atomic_bool started_; - atomic_bool join_called_; + std::atomic_bool started_{false}; + std::atomic_bool join_called_{false}; Semaphore join_sema_; }; @@ -74,7 +74,7 @@ starboard::Semaphore* Thread::join_sema() { return &d_->join_sema_; } -starboard::atomic_bool* Thread::joined_bool() { +std::atomic_bool* Thread::joined_bool() { return &d_->join_called_; } diff --git a/starboard/common/thread.h b/starboard/common/thread.h index 1ac5a19d47c3..9e0af365ec78 100644 --- a/starboard/common/thread.h +++ b/starboard/common/thread.h @@ -17,6 +17,7 @@ #ifndef STARBOARD_COMMON_THREAD_H_ #define STARBOARD_COMMON_THREAD_H_ +#include #include #include #include @@ -28,7 +29,6 @@ namespace starboard { class Semaphore; -class atomic_bool; class Thread { public: @@ -64,7 +64,7 @@ class Thread { // Join() was called then return |true|, else |false|. bool WaitForJoin(int64_t timeout); Semaphore* join_sema(); - atomic_bool* joined_bool(); + std::atomic_bool* joined_bool(); struct Data; std::unique_ptr d_; diff --git a/starboard/elf_loader/exported_symbols.cc b/starboard/elf_loader/exported_symbols.cc index 97d5d3d39482..48f816a36374 100644 --- a/starboard/elf_loader/exported_symbols.cc +++ b/starboard/elf_loader/exported_symbols.cc @@ -174,23 +174,29 @@ ExportedSymbols::ExportedSymbols() { REGISTER_SYMBOL(SbEventCancel); REGISTER_SYMBOL(SbEventSchedule); REGISTER_SYMBOL(SbFileAtomicReplace); +#if SB_API_VERSION < 17 REGISTER_SYMBOL(SbFileCanOpen); REGISTER_SYMBOL(SbFileClose); REGISTER_SYMBOL(SbFileDelete); +#endif // SB_API_VERSION < 17 #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbFileExists); #endif // SB_API_VERSION < 16 +#if SB_API_VERSION < 17 REGISTER_SYMBOL(SbFileFlush); REGISTER_SYMBOL(SbFileGetInfo); +#endif // SB_API_VERSION < 17 #if SB_API_VERSION < 16 REGISTER_SYMBOL(SbFileGetPathInfo); #endif // SB_API_VERSION < 16 +#if SB_API_VERSION < 17 REGISTER_SYMBOL(SbFileModeStringToFlags); REGISTER_SYMBOL(SbFileOpen); REGISTER_SYMBOL(SbFileRead); REGISTER_SYMBOL(SbFileSeek); REGISTER_SYMBOL(SbFileTruncate); REGISTER_SYMBOL(SbFileWrite); +#endif // SB_API_VERSION < 17 REGISTER_SYMBOL(SbGetEglInterface); REGISTER_SYMBOL(SbGetGlesInterface); #if SB_API_VERSION < 16 @@ -261,17 +267,31 @@ ExportedSymbols::ExportedSymbols() { #endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbPlayerCreate); REGISTER_SYMBOL(SbPlayerDestroy); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetAudioConfiguration); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetCurrentFrame); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetInfo); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerGetInfo2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerGetMaximumNumberOfSamplesPerWrite); REGISTER_SYMBOL(SbPlayerGetPreferredOutputMode); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerSeek); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerSeek2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerSetBounds); REGISTER_SYMBOL(SbPlayerSetPlaybackRate); REGISTER_SYMBOL(SbPlayerSetVolume); REGISTER_SYMBOL(SbPlayerWriteEndOfStream); +#if SB_API_VERSION >= 15 REGISTER_SYMBOL(SbPlayerWriteSamples); +#else // SB_API_VERSION >= 15 + REGISTER_SYMBOL(SbPlayerWriteSample2); +#endif // SB_API_VERSION >= 15 REGISTER_SYMBOL(SbSocketAccept); REGISTER_SYMBOL(SbSocketBind); REGISTER_SYMBOL(SbSocketClearLastError); @@ -327,6 +347,9 @@ ExportedSymbols::ExportedSymbols() { #endif // SB_API_VERSION < 16 REGISTER_SYMBOL(SbSystemBreakIntoDebugger); REGISTER_SYMBOL(SbSystemClearLastError); +#if SB_API_VERSION < 15 + REGISTER_SYMBOL(SbSystemGetDeviceType); +#endif REGISTER_SYMBOL(SbSystemGetErrorString); REGISTER_SYMBOL(SbSystemGetExtension); REGISTER_SYMBOL(SbSystemGetLastError); diff --git a/starboard/elf_loader/file_impl.cc b/starboard/elf_loader/file_impl.cc index 951db5fdbc09..96a0ec81cc4c 100644 --- a/starboard/elf_loader/file_impl.cc +++ b/starboard/elf_loader/file_impl.cc @@ -14,6 +14,10 @@ #include "starboard/elf_loader/file_impl.h" +#include +#include + +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/elf_loader/log.h" @@ -31,7 +35,7 @@ void LogLastError(const char* msg) { namespace starboard { namespace elf_loader { -FileImpl::FileImpl() : file_(NULL) {} +FileImpl::FileImpl() : file_(-1) {} FileImpl::~FileImpl() { Close(); @@ -40,7 +44,7 @@ FileImpl::~FileImpl() { bool FileImpl::Open(const char* name) { SB_DLOG(INFO) << "Loading: " << name; name_ = name; - file_ = SbFileOpen(name, kSbFileOpenOnly | kSbFileRead, NULL, NULL); + file_ = open(name, O_RDONLY, S_IRUSR | S_IWUSR); if (!file_) { return false; } @@ -51,17 +55,17 @@ bool FileImpl::ReadFromOffset(int64_t offset, char* buffer, int size) { if (!file_) { return false; } - int64_t ret = SbFileSeek(file_, kSbFileFromBegin, offset); - SB_DLOG(INFO) << "SbFileSeek: ret=" << ret; + int64_t ret = lseek(file_, offset, SEEK_SET); + SB_DLOG(INFO) << "lseek: ret=" << ret; if (ret == -1) { - LogLastError("SbFileSeek: failed"); + LogLastError("lseek: failed"); return false; } - int count = SbFileReadAll(file_, buffer, size); - SB_DLOG(INFO) << "SbFileReadAll: count=" << count; + int count = starboard::ReadAll(file_, buffer, size); + SB_DLOG(INFO) << "ReadAll: count=" << count; if (count == -1) { - LogLastError("SbFileReadAll failed"); + LogLastError("ReadAll failed"); return false; } return true; @@ -69,7 +73,7 @@ bool FileImpl::ReadFromOffset(int64_t offset, char* buffer, int size) { void FileImpl::Close() { if (file_) { - SbFileClose(file_); + close(file_); } } diff --git a/starboard/elf_loader/file_impl.h b/starboard/elf_loader/file_impl.h index a6a30bdc8cf2..a1a2f9525be5 100644 --- a/starboard/elf_loader/file_impl.h +++ b/starboard/elf_loader/file_impl.h @@ -35,7 +35,7 @@ class FileImpl : public File { const std::string& GetName() override; protected: - SbFile file_; + int file_; std::string name_; FileImpl(const FileImpl&) = delete; diff --git a/starboard/elf_loader/lz4_file_impl.cc b/starboard/elf_loader/lz4_file_impl.cc index 1ffbdfa921ab..9285f62ce2d5 100644 --- a/starboard/elf_loader/lz4_file_impl.cc +++ b/starboard/elf_loader/lz4_file_impl.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include #include @@ -73,9 +75,9 @@ bool LZ4FileImpl::Open(const char* name) { return false; } - SbFileInfo file_info; + struct stat file_info; - if (!FileImpl::Open(name) || !SbFileGetInfo(file_, &file_info)) { + if (!FileImpl::Open(name) || fstat(file_, &file_info)) { return false; } @@ -111,7 +113,7 @@ bool LZ4FileImpl::Open(const char* name) { // uncompressed block size. int max_compressed_buffer_size = GetBlockSize(&frame_info); - bool result = Decompress(file_info.size, header_size, + bool result = Decompress(file_info.st_size, header_size, max_compressed_buffer_size, source_bytes_hint); int64_t decompression_end_time_us = CurrentMonotonicTime(); diff --git a/starboard/event.h b/starboard/event.h index 119a94d72676..b7f245559b3b 100644 --- a/starboard/event.h +++ b/starboard/event.h @@ -345,12 +345,14 @@ static SB_C_FORCE_INLINE bool SbEventIsIdValid(SbEventId handle) { return handle != kSbEventIdInvalid; } +#if SB_API_VERSION >= 15 typedef void (*SbEventHandleCallback)(const SbEvent* event); // Serves as the entry point in the Starboard library for running the Starboard // event loop with the application event handler. SB_EXPORT int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback); +#endif // SB_API_VERSION >= 15 // The entry point that Starboard applications MUST implement. Any memory // pointed at by |event| or the |data| field inside |event| is owned by the // system, and that memory is reclaimed after this function returns, so the @@ -362,7 +364,11 @@ SB_EXPORT int SbRunStarboardMain(int argc, // specification about what other work might happen on this thread, so the // application should generally do as little work as possible on this thread, // and just dispatch it over to another thread. +#if SB_API_VERSION >= 15 SB_EXPORT_PLATFORM void SbEventHandle(const SbEvent* event); +#else +SB_IMPORT void SbEventHandle(const SbEvent* event); +#endif // SB_API_VERSION >= 15 // Schedules an event |callback| into the main Starboard event loop. // This function may be called from any thread, but |callback| is always diff --git a/starboard/extension/enhanced_audio_test.cc b/starboard/extension/enhanced_audio_test.cc index c2c7563aac78..c11598ba7c33 100644 --- a/starboard/extension/enhanced_audio_test.cc +++ b/starboard/extension/enhanced_audio_test.cc @@ -24,6 +24,8 @@ namespace starboard { namespace extension { +#if SB_API_VERSION >= 15 + TEST(EnhancedAudioTest, VerifyBinaryLayouts) { // Sanity check that the layouts of the extension specific types are the same // as corresponding SbMedia and SbPlayer types. @@ -108,5 +110,7 @@ TEST(EnhancedAudioTest, VerifyBinaryLayouts) { offsetof(SbPlayerSampleInfo, drm_info)); } +#endif // SB_API_VERSION >= 15 + } // namespace extension } // namespace starboard diff --git a/starboard/extension/extension_test.cc b/starboard/extension/extension_test.cc index 6b6472e43212..5d320292351f 100644 --- a/starboard/extension/extension_test.cc +++ b/starboard/extension/extension_test.cc @@ -403,6 +403,7 @@ TEST(ExtensionTest, EnhancedAudio) { return; } +#if SB_API_VERSION >= 15 ASSERT_FALSE(extension_api) << "EnhancedAudio extension shouldn't be used under SB_API_VERSION " << SB_API_VERSION @@ -412,6 +413,7 @@ TEST(ExtensionTest, EnhancedAudio) { << " implementation to `SbPlayerWriteSample()` (as they are compatible" << " at abi level) and disable the EnhancedAudio extension from" << " `SbSystemGetExtension()`."; +#endif // SB_API_VERSION >= 15 EXPECT_STREQ(extension_api->name, kExtensionName); EXPECT_EQ(extension_api->version, 1u); diff --git a/starboard/file.h b/starboard/file.h index 9a54ef79501f..ead07597879a 100644 --- a/starboard/file.h +++ b/starboard/file.h @@ -127,6 +127,8 @@ static inline bool SbFileIsValid(SbFile file) { return file != kSbFileInvalid; } +#if SB_API_VERSION < 17 + // DEPRECATED with SB_API_VERSION 16 // // Opens the file at |path|, which must be absolute, creating it if specified by @@ -158,6 +160,8 @@ SB_EXPORT SbFile SbFileOpen(const char* path, // |file|: The absolute path of the file to be closed. SB_EXPORT bool SbFileClose(SbFile file); +#endif // SB_API_VERSION < 17 + // Replaces the content of the file at |path| with |data|. Returns whether the // contents of the file were replaced. The replacement of the content is an // atomic operation. The file will either have all of the data, or none. @@ -169,6 +173,8 @@ SB_EXPORT bool SbFileAtomicReplace(const char* path, const char* data, int64_t data_size); +#if SB_API_VERSION < 17 + // DEPRECATED with SB_API_VERSION 16 // // Changes the current read/write position in |file|. The return value @@ -264,6 +270,8 @@ SB_EXPORT bool SbFileGetPathInfo(const char* path, SbFileInfo* out_info); // |path|: The absolute path of the file, symlink, or directory to be deleted. SB_EXPORT bool SbFileDelete(const char* path); +#endif // SB_API_VERSION < 17 + #if SB_API_VERSION < 16 // Indicates whether a file or directory exists at |path|. // @@ -271,6 +279,8 @@ SB_EXPORT bool SbFileDelete(const char* path); SB_EXPORT bool SbFileExists(const char* path); #endif // SB_API_VERSION < 16 +#if SB_API_VERSION < 17 + // DEPRECATED with SB_API_VERSION 16 // // Indicates whether SbFileOpen() with the given |flags| is allowed for |path|. @@ -346,6 +356,8 @@ static inline int SbFileWriteAll(SbFile file, const char* data, int size) { return bytes_written ? bytes_written : rv; } +#endif // SB_API_VERSION < 17 + #ifdef __cplusplus } // extern "C" #endif diff --git a/starboard/key.h b/starboard/key.h index d71ec2f06e04..a0762f416bba 100644 --- a/starboard/key.h +++ b/starboard/key.h @@ -215,7 +215,9 @@ typedef enum SbKey { kSbKeyYellow = 0x195, kSbKeyBlue = 0x196, +#if SB_API_VERSION >= 15 kSbKeyRecord = 0x1A0, +#endif kSbKeyChannelUp = 0x1AB, kSbKeyChannelDown = 0x1AC, kSbKeySubtitle = 0x1CC, diff --git a/starboard/linux/shared/BUILD.gn b/starboard/linux/shared/BUILD.gn index 53838e95b4d2..ab821f26960c 100644 --- a/starboard/linux/shared/BUILD.gn +++ b/starboard/linux/shared/BUILD.gn @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//starboard/shared/enhanced_audio/enhanced_audio.gni") import("//starboard/shared/starboard/media/media_tests.gni") import("//starboard/shared/starboard/player/buildfiles.gni") import("//starboard/shared/starboard/player/player_tests.gni") @@ -86,6 +87,7 @@ static_library("starboard_platform_sources") { "//starboard/linux/shared/routes.h", "//starboard/linux/shared/soft_mic_platform_service.cc", "//starboard/linux/shared/soft_mic_platform_service.h", + "//starboard/linux/shared/system_get_device_type.cc", "//starboard/linux/shared/system_get_extensions.cc", "//starboard/linux/shared/system_get_path.cc", "//starboard/linux/shared/system_has_capability.cc", diff --git a/starboard/linux/shared/system_get_device_type.cc b/starboard/linux/shared/system_get_device_type.cc new file mode 100644 index 000000000000..ba90dbc08077 --- /dev/null +++ b/starboard/linux/shared/system_get_device_type.cc @@ -0,0 +1,23 @@ +// Copyright 2016 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + return kSbSystemDeviceTypeDesktopPC; +} + +#endif diff --git a/starboard/linux/shared/system_get_extensions.cc b/starboard/linux/shared/system_get_extensions.cc index 1dad8044a8e8..454bf3abe3f8 100644 --- a/starboard/linux/shared/system_get_extensions.cc +++ b/starboard/linux/shared/system_get_extensions.cc @@ -34,6 +34,7 @@ #include "starboard/linux/shared/ifa.h" #include "starboard/linux/shared/platform_service.h" #include "starboard/linux/shared/time_zone.h" +#include "starboard/shared/enhanced_audio/enhanced_audio.h" #include "starboard/shared/ffmpeg/ffmpeg_demuxer.h" #include "starboard/shared/posix/free_space.h" #include "starboard/shared/posix/memory_mapped_file.h" @@ -70,6 +71,11 @@ const void* SbSystemGetExtension(const char* name) { if (strcmp(name, kCobaltExtensionFreeSpaceName) == 0) { return starboard::shared::posix::GetFreeSpaceApi(); } +#if SB_API_VERSION < 15 + if (strcmp(name, kCobaltExtensionEnhancedAudioName) == 0) { + return starboard::shared::enhanced_audio::GetEnhancedAudioApi(); + } +#endif // SB_API_VERSION < 15 if (strcmp(name, kCobaltExtensionDemuxerApi) == 0) { auto command_line = starboard::shared::starboard::Application::Get()->GetCommandLine(); diff --git a/starboard/linux/x64x11/main.cc b/starboard/linux/x64x11/main.cc index 54dd41a96d0b..58137c4e2778 100644 --- a/starboard/linux/x64x11/main.cc +++ b/starboard/linux/x64x11/main.cc @@ -62,7 +62,16 @@ extern "C" SB_EXPORT_PLATFORM int main(int argc, char** argv) { SbLogRawDumpStack(3); #endif +#if SB_API_VERSION >= 15 int result = SbRunStarboardMain(argc, argv, SbEventHandle); +#else + starboard::shared::x11::ApplicationX11 application; + int result = 0; + { + starboard::shared::starboard::LinkReceiver receiver(&application); + result = application.Run(argc, argv); + } +#endif // SB_API_VERSION >= 15 starboard::shared::signal::UninstallSuspendSignalHandlers(); starboard::shared::signal::UninstallDebugSignalHandlers(); starboard::shared::signal::UninstallCrashSignalHandlers(); diff --git a/starboard/linux/x64x11/run_starboard_main.cc b/starboard/linux/x64x11/run_starboard_main.cc index 96b605f96a68..813e1df5716e 100644 --- a/starboard/linux/x64x11/run_starboard_main.cc +++ b/starboard/linux/x64x11/run_starboard_main.cc @@ -17,6 +17,7 @@ #include "starboard/shared/starboard/link_receiver.h" #include "starboard/shared/x11/application_x11.h" +#if SB_API_VERSION >= 15 int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { starboard::shared::x11::ApplicationX11 application(callback); int result = 0; @@ -26,3 +27,4 @@ int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { } return result; } +#endif // SB_API_VERSION >= 15 diff --git a/starboard/linux/x64x11/system_get_property_impl.cc b/starboard/linux/x64x11/system_get_property_impl.cc index b10471c65ceb..5612b2d7c300 100644 --- a/starboard/linux/x64x11/system_get_property_impl.cc +++ b/starboard/linux/x64x11/system_get_property_impl.cc @@ -129,9 +129,11 @@ bool GetSystemProperty(SbSystemPropertyId property_id, return CopyStringAndTestIfSuccess( out_value, value_length, GetEnvironment("COBALT_LIMIT_AD_TRACKING").c_str()); +#if SB_API_VERSION >= 15 case kSbSystemPropertyDeviceType: return CopyStringAndTestIfSuccess(out_value, value_length, kSystemDeviceTypeDesktopPC); +#endif default: SB_DLOG(WARNING) << __FUNCTION__ << ": Unrecognized property: " << property_id; diff --git a/starboard/loader_app/app_key_files_test.cc b/starboard/loader_app/app_key_files_test.cc index 870fcf17f18d..15207c4a106d 100644 --- a/starboard/loader_app/app_key_files_test.cc +++ b/starboard/loader_app/app_key_files_test.cc @@ -15,6 +15,7 @@ #include "starboard/loader_app/app_key_files.h" #include +#include #include #include @@ -53,24 +54,24 @@ TEST_F(AppKeyFilesTest, TestGoodKeyFile) { std::string file_path = GetGoodAppKeyFilePath(dir_, kTestAppKey); ASSERT_FALSE(file_path.empty()); if (FileExists(file_path.c_str())) { - SbFileDelete(file_path.c_str()); + unlink(file_path.c_str()); } ASSERT_FALSE(FileExists(file_path.c_str())); ASSERT_TRUE(CreateAppKeyFile(file_path)); ASSERT_TRUE(FileExists(file_path.c_str())); - SbFileDelete(file_path.c_str()); + unlink(file_path.c_str()); } TEST_F(AppKeyFilesTest, TestBadKeyFile) { std::string file_path = GetBadAppKeyFilePath(dir_, kTestAppKey); ASSERT_FALSE(file_path.empty()); if (FileExists(file_path.c_str())) { - SbFileDelete(file_path.c_str()); + unlink(file_path.c_str()); } ASSERT_FALSE(FileExists(file_path.c_str())); ASSERT_TRUE(CreateAppKeyFile(file_path)); ASSERT_TRUE(FileExists(file_path.c_str())); - SbFileDelete(file_path.c_str()); + unlink(file_path.c_str()); } TEST_F(AppKeyFilesTest, TestGoodKeyFileInvalidInput) { @@ -96,7 +97,7 @@ TEST_F(AppKeyFilesTest, TestAnyGoodKeyFile) { ASSERT_TRUE(CreateAppKeyFile(file_path)); ASSERT_TRUE(FileExists(file_path.c_str())); ASSERT_TRUE(AnyGoodAppKeyFile(dir_)); - SbFileDelete(file_path.c_str()); + unlink(file_path.c_str()); } } // namespace diff --git a/starboard/loader_app/drain_file.cc b/starboard/loader_app/drain_file.cc index cc4c57c3daec..be45051d9d1f 100644 --- a/starboard/loader_app/drain_file.cc +++ b/starboard/loader_app/drain_file.cc @@ -15,6 +15,8 @@ #include "starboard/loader_app/drain_file.h" #include +#include +#include #include #include @@ -176,12 +178,10 @@ bool TryDrain(const char* dir, const char* app_key) { path.append(kSbFileSepString); path.append(filename); - SbFileError error = kSbFileOk; - SbFile file = SbFileOpen(path.c_str(), kSbFileCreateAlways | kSbFileWrite, - NULL, &error); + int file = open(path.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); - SB_DCHECK(error == kSbFileOk); - SB_DCHECK(SbFileClose(file)); + SB_DCHECK(file >= 0); + SB_DCHECK(close(file) == 0); SB_LOG(INFO) << "Created drain file at '" << path << "'"; @@ -208,7 +208,7 @@ void ClearExpired(const char* dir) { continue; } const std::string path = dir + std::string(kSbFileSepString) + filename; - if (!SbFileDelete(path.c_str())) { + if (unlink(path.c_str())) { SB_LOG(ERROR) << "Failed to remove expired drain file at '" << path << "'"; } @@ -225,7 +225,7 @@ void ClearForApp(const char* dir, const char* app_key) { for (const auto& filename : filenames) { const std::string path = dir + std::string(kSbFileSepString) + filename; - if (!SbFileDelete(path.c_str())) { + if (unlink(path.c_str())) { SB_LOG(ERROR) << "Failed to remove drain file at '" << path << "'"; } } diff --git a/starboard/loader_app/drain_file_helper.cc b/starboard/loader_app/drain_file_helper.cc index 3c25efbf704a..5e883ec4cb3f 100644 --- a/starboard/loader_app/drain_file_helper.cc +++ b/starboard/loader_app/drain_file_helper.cc @@ -15,6 +15,7 @@ #include "starboard/loader_app/drain_file_helper.h" #include +#include #include "starboard/common/file.h" #include "starboard/loader_app/drain_file.h" @@ -41,7 +42,7 @@ ScopedDrainFile::ScopedDrainFile(const std::string& dir, ScopedDrainFile::~ScopedDrainFile() { if (!Exists()) return; - EXPECT_TRUE(SbFileDelete(path_.c_str())); + EXPECT_TRUE(!unlink(path_.c_str())); } bool ScopedDrainFile::Exists() const { diff --git a/starboard/loader_app/drain_file_test.cc b/starboard/loader_app/drain_file_test.cc index 2f23686a6f0f..680cc3554009 100644 --- a/starboard/loader_app/drain_file_test.cc +++ b/starboard/loader_app/drain_file_test.cc @@ -184,13 +184,13 @@ TEST_F(DrainFileTest, SunnyDayRankCorrectlyRanksFiles) { std::vector result(kSbFileMaxName); EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "a")); - EXPECT_TRUE(SbFileDelete(early_and_least.path().c_str())); + EXPECT_TRUE(!unlink(early_and_least.path().c_str())); EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "c")); - EXPECT_TRUE(SbFileDelete(later_and_least.path().c_str())); + EXPECT_TRUE(!unlink(later_and_least.path().c_str())); EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "b")); - EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str())); + EXPECT_TRUE(!unlink(later_and_greatest.path().c_str())); } // Ranking drain files should ignore expired files. @@ -206,14 +206,14 @@ TEST_F(DrainFileTest, SunnyDayRankCorrectlyIgnoresExpired) { std::vector result(kSbFileMaxName); EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "c")); - EXPECT_TRUE(SbFileDelete(later_and_least.path().c_str())); + EXPECT_TRUE(!unlink(later_and_least.path().c_str())); EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "b")); - EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str())); + EXPECT_TRUE(!unlink(later_and_greatest.path().c_str())); // Even though "a" is still there Rank should find nothing since it's expired. EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "")); - EXPECT_TRUE(SbFileDelete(early_and_expired.path().c_str())); + EXPECT_TRUE(!unlink(early_and_expired.path().c_str())); } // Tests the "racing updaters" scenario. diff --git a/starboard/loader_app/installation_manager.cc b/starboard/loader_app/installation_manager.cc index e8ad17169043..73ef2cf2f3b6 100644 --- a/starboard/loader_app/installation_manager.cc +++ b/starboard/loader_app/installation_manager.cc @@ -14,7 +14,9 @@ #include "starboard/loader_app/installation_manager.h" +#include #include +#include #include #include @@ -28,7 +30,6 @@ #include "starboard/configuration_constants.h" #include "starboard/directory.h" #include "starboard/extension/loader_app_metrics.h" -#include "starboard/file.h" #include "starboard/loader_app/installation_store.pb.h" #if !SB_IS(EVERGREEN_COMPATIBLE_LITE) #include "starboard/loader_app/pending_restart.h" // nogncheck @@ -657,28 +658,27 @@ void InstallationManager::ValidatePriorities() { } bool InstallationManager::LoadInstallationStore() { - SbFile file; + int file; SB_LOG(INFO) << "StorePath=" << store_path_; - file = SbFileOpen(store_path_.c_str(), kSbFileOpenOnly | kSbFileRead, NULL, - NULL); - if (!file) { + file = open(store_path_.c_str(), O_RDONLY, S_IRUSR | S_IWUSR); + if (!starboard::IsValid(file)) { SB_LOG(WARNING) << "Failed to open file: " << store_path_; return false; } char buf[IM_MAX_INSTALLATION_STORE_SIZE]; - int count = SbFileReadAll(file, buf, IM_MAX_INSTALLATION_STORE_SIZE); - SB_DLOG(INFO) << "SbFileReadAll: count=" << count; + int count = starboard::ReadAll(file, buf, IM_MAX_INSTALLATION_STORE_SIZE); + SB_DLOG(INFO) << "ReadAll: count=" << count; if (count == -1) { - LogLastSystemError("SbFileReadAll failed"); + LogLastSystemError("ReadAll failed"); return false; } if (!installation_store_.ParseFromArray(buf, count)) { SB_LOG(ERROR) << "LoadInstallationStore: Unable to parse storage"; return false; } - SbFileClose(file); + close(file); return true; } diff --git a/starboard/loader_app/installation_manager_test.cc b/starboard/loader_app/installation_manager_test.cc index 1a3564a5c24d..daec5c62b0a5 100644 --- a/starboard/loader_app/installation_manager_test.cc +++ b/starboard/loader_app/installation_manager_test.cc @@ -15,7 +15,9 @@ #include "starboard/loader_app/installation_manager.h" #include +#include #include +#include #include #include @@ -71,18 +73,17 @@ class InstallationManagerTest : public ::testing::TestWithParam { } void ReadStorageState(cobalt::loader::InstallationStore* installation_store) { - SbFile file; + int file; - file = SbFileOpen(installation_store_path_.c_str(), - kSbFileOpenOnly | kSbFileRead, NULL, NULL); - ASSERT_TRUE(file); + file = open(installation_store_path_.c_str(), O_RDONLY, S_IRUSR | S_IWUSR); + ASSERT_TRUE(file >= 0); char buf[IM_MAX_INSTALLATION_STORE_SIZE]; - int count = SbFileReadAll(file, buf, IM_MAX_INSTALLATION_STORE_SIZE); - SB_DLOG(INFO) << "SbFileReadAll: count=" << count; + int count = starboard::ReadAll(file, buf, IM_MAX_INSTALLATION_STORE_SIZE); + SB_DLOG(INFO) << "ReadAll: count=" << count; ASSERT_NE(-1, count); ASSERT_TRUE(installation_store->ParseFromArray(buf, count)); - SbFileClose(file); + close(file); } // Roll forward to |index| installation in a |max_num_installations| @@ -200,11 +201,11 @@ class InstallationManagerTest : public ::testing::TestWithParam { std::string full_path = storage_path_; full_path += kSbFileSepString; full_path += dir_entry.data(); - SbFileDelete(full_path.c_str()); + unlink(full_path.c_str()); } closedir(directory); - SbFileDelete(storage_path_.c_str()); + rmdir(storage_path_.c_str()); } protected: diff --git a/starboard/loader_app/slot_management_test.cc b/starboard/loader_app/slot_management_test.cc index e867175d2c1e..8b98ed9c22de 100644 --- a/starboard/loader_app/slot_management_test.cc +++ b/starboard/loader_app/slot_management_test.cc @@ -14,8 +14,10 @@ #include "starboard/loader_app/slot_management.h" +#include #include #include +#include #include #include @@ -244,10 +246,9 @@ class SlotManagementTest : public testing::TestWithParam { path += kSbFileSepString; path += "libcobalt"; AddFileExtension(path); - SbFile sb_file = SbFileOpen(path.c_str(), kSbFileOpenAlways | kSbFileRead, - nullptr, nullptr); - EXPECT_TRUE(SbFileIsValid(sb_file)); - SbFileClose(sb_file); + int sb_file = open(path.c_str(), O_CREAT | O_RDONLY); + EXPECT_TRUE(starboard::IsValid(sb_file)); + close(sb_file); return !top_created_dir.empty() ? top_created_dir : path; } diff --git a/starboard/media.h b/starboard/media.h index c067426e9247..182e8000e91e 100644 --- a/starboard/media.h +++ b/starboard/media.h @@ -65,7 +65,9 @@ typedef enum SbMediaAudioCodec { kSbMediaAudioCodecMp3, kSbMediaAudioCodecFlac, kSbMediaAudioCodecPcm, +#if SB_API_VERSION >= 15 kSbMediaAudioCodecIamf, +#endif // SB_API_VERSION >= 15 } SbMediaAudioCodec; // Indicates how confident the device is that it can play media resources of the @@ -85,17 +87,28 @@ typedef enum SbMediaSupportType { // Possible audio connector types. typedef enum SbMediaAudioConnector { +#if SB_API_VERSION >= 15 kSbMediaAudioConnectorUnknown, +#else // SB_API_VERSION >= 15 + kSbMediaAudioConnectorNone, +#endif // SB_API_VERSION >= 15 + kSbMediaAudioConnectorAnalog, kSbMediaAudioConnectorBluetooth, +#if SB_API_VERSION >= 15 kSbMediaAudioConnectorBuiltIn, +#endif // SB_API_VERSION >= 15 kSbMediaAudioConnectorHdmi, +#if SB_API_VERSION >= 15 // A wired remote audio output, like a remote speaker via Ethernet. kSbMediaAudioConnectorRemoteWired, // A wireless remote audio output, like a remote speaker via Wi-Fi. kSbMediaAudioConnectorRemoteWireless, // A remote audio output cannot be classified into other existing types. kSbMediaAudioConnectorRemoteOther, +#else // SB_API_VERSION >= 15 + kSbMediaAudioConnectorNetwork, +#endif // SB_API_VERSION >= 15 kSbMediaAudioConnectorSpdif, kSbMediaAudioConnectorUsb, } SbMediaAudioConnector; @@ -374,6 +387,8 @@ typedef struct SbMediaColorMetadata { float custom_primary_matrix[12]; } SbMediaColorMetadata; +#if SB_API_VERSION >= 15 + // The set of information required by the decoder or player for each video // stream. typedef struct SbMediaVideoStreamInfo { @@ -429,6 +444,58 @@ typedef struct SbMediaVideoSampleInfo { bool is_key_frame; } SbMediaVideoSampleInfo; +#else // SB_API_VERSION >= 15 + +// The set of information required by the decoder or player for each video +// sample. +typedef struct SbMediaVideoSampleInfo { + // The video codec of this sample. + SbMediaVideoCodec codec; + + // The mime of the video stream when |codec| isn't kSbMediaVideoCodecNone. It + // may point to an empty string if the mime is not available, and it can only + // be set to NULL when |codec| is kSbMediaVideoCodecNone. + const char* mime; + + // Indicates the max video capabilities required. The web app will not provide + // a video stream exceeding the maximums described by this parameter. Allows + // the platform to optimize playback pipeline for low quality video streams if + // it knows that it will never adapt to higher quality streams. The string + // uses the same format as the string passed in to + // SbMediaCanPlayMimeAndKeySystem(), for example, when it is set to + // "width=1920; height=1080; framerate=15;", the video will never adapt to + // resolution higher than 1920x1080 or frame per second higher than 15 fps. + // When the maximums are unknown, this will be set to an empty string. It can + // only be set to NULL when |codec| is kSbMediaVideoCodecNone. + const char* max_video_capabilities; + + // Indicates whether the associated sample is a key frame (I-frame). Video key + // frames must always start with SPS and PPS NAL units. + bool is_key_frame; + + // The frame width of this sample, in pixels. Also could be parsed from the + // Sequence Parameter Set (SPS) NAL Unit. Frame dimensions must only change on + // key frames, but may change on any key frame. + int frame_width; + + // The frame height of this sample, in pixels. Also could be parsed from the + // Sequence Parameter Set (SPS) NAL Unit. Frame dimensions must only change on + // key frames, but may change on any key frame. + int frame_height; + + // HDR metadata common for HDR10 and WebM/VP9-based HDR formats as + // well as the Color Space, and Color elements: MatrixCoefficients, + // BitsPerChannel, ChromaSubsamplingHorz, ChromaSubsamplingVert, + // CbSubsamplingHorz, CbSubsamplingVert, ChromaSitingHorz, + // ChromaSitingVert, Range, TransferCharacteristics, and Primaries + // described here: https://matroska.org/technical/specs/index.html . + // This will only be specified on frames where the HDR metadata and + // color / color space might have changed (e.g. keyframes). + SbMediaColorMetadata color_metadata; +} SbMediaVideoSampleInfo, SbMediaVideoStreamInfo; + +#endif // SB_API_VERSION >= 15 + // A structure describing the audio configuration parameters of a single audio // output. typedef struct SbMediaAudioConfiguration { @@ -437,8 +504,13 @@ typedef struct SbMediaAudioConfiguration { int index; #endif // SB_API_VERSION < 15 +#if SB_API_VERSION >= 15 // The type of audio connector. Will be |kSbMediaAudioConnectorUnknown| if // this device cannot provide this information. +#else // SB_API_VERSION >= 15 + // The type of audio connector. Will be the empty |kSbMediaAudioConnectorNone| + // if this device cannot provide this information. +#endif // SB_API_VERSION >= 15 SbMediaAudioConnector connector; // The expected latency of audio over this output, in microseconds, or |0| if @@ -454,6 +526,8 @@ typedef struct SbMediaAudioConfiguration { int number_of_channels; } SbMediaAudioConfiguration; +#if SB_API_VERSION >= 15 + // The set of information required by the decoder or player for each audio // stream. typedef struct SbMediaAudioStreamInfo { @@ -490,6 +564,51 @@ typedef struct SbMediaAudioSampleInfo { int64_t discarded_duration_from_back; // in microseconds. } SbMediaAudioSampleInfo; +#else // SB_API_VERSION >= 15 + +// An audio sample info, which is a description of a given audio sample. This +// acts as a set of instructions to the audio decoder. +// +// The audio sample info consists of information found in the |WAVEFORMATEX| +// structure, as well as other information for the audio decoder, including the +// Audio-specific configuration field. The |WAVEFORMATEX| structure is +// specified at http://msdn.microsoft.com/en-us/library/dd390970(v=vs.85).aspx . +typedef struct SbMediaAudioSampleInfo { + // The audio codec of this sample. + SbMediaAudioCodec codec; + + // The mime of the audio stream when |codec| isn't kSbMediaAudioCodecNone. It + // may point to an empty string if the mime is not available, and it can only + // be set to NULL when |codec| is kSbMediaAudioCodecNone. + const char* mime; + + // The waveform-audio format type code. + uint16_t format_tag; + + // The number of audio channels in this format. |1| for mono, |2| for stereo. + uint16_t number_of_channels; + + // The sampling rate. + uint32_t samples_per_second; + + // The number of bytes per second expected with this format. + uint32_t average_bytes_per_second; + + // Byte block alignment, e.g., 4. + uint16_t block_alignment; + + // The bit depth for the stream this represents, e.g. |8| or |16|. + uint16_t bits_per_sample; + + // The size, in bytes, of the audio_specific_config. + uint16_t audio_specific_config_size; + + // The AudioSpecificConfig, as specified in ISO/IEC-14496-3, section 1.6.2.1. + const void* audio_specific_config; +} SbMediaAudioSampleInfo, SbMediaAudioStreamInfo; + +#endif // SB_API_VERSION >= 15 + // --- Functions ------------------------------------------------------------- // Returns information about whether the playback of the specific media diff --git a/starboard/nplb/BUILD.gn b/starboard/nplb/BUILD.gn index fed8b32eb861..57c3745537ff 100644 --- a/starboard/nplb/BUILD.gn +++ b/starboard/nplb/BUILD.gn @@ -146,12 +146,14 @@ target(gtest_target_type, "nplb") { "posix_compliance/posix_directory_create_test.cc", "posix_compliance/posix_directory_get_next_test.cc", "posix_compliance/posix_directory_open_test.cc", + "posix_compliance/posix_file_can_open_test.cc", "posix_compliance/posix_file_close_test.cc", "posix_compliance/posix_file_delete_test.cc", "posix_compliance/posix_file_fsync_test.cc", "posix_compliance/posix_file_ftruncate_test.cc", "posix_compliance/posix_file_get_info_test.cc", "posix_compliance/posix_file_get_path_info_test.cc", + "posix_compliance/posix_file_mode_string_to_flags_test.cc", "posix_compliance/posix_file_open_test.cc", "posix_compliance/posix_file_read_test.cc", "posix_compliance/posix_file_seek_test.cc", @@ -303,6 +305,7 @@ target(gtest_target_type, "nplb") { deps = [ "//starboard:starboard_group", "//starboard/common", + "//starboard/common:file_wrapper", "//starboard/nplb/compiler_compliance:cpp14_supported", "//starboard/shared/starboard/media:media_util", "//starboard/shared/starboard/player:video_dmp", diff --git a/starboard/nplb/file_atomic_replace_test.cc b/starboard/nplb/file_atomic_replace_test.cc index c13330b41035..9b63835db1cd 100644 --- a/starboard/nplb/file_atomic_replace_test.cc +++ b/starboard/nplb/file_atomic_replace_test.cc @@ -12,8 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include #include +#include "starboard/common/file.h" #include "starboard/file.h" #include "starboard/nplb/file_helpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -31,17 +33,15 @@ bool CompareFileContentsToString(const char* filename, int size) { char result[kTestContentsLength] = {'\0'}; - SbFileError error; - SbFile file = - SbFileOpen(filename, kSbFileOpenOnly | kSbFileRead, nullptr, &error); + int file = open(filename, O_RDONLY, S_IRUSR | S_IWUSR); - EXPECT_EQ(kSbFileOk, error); + EXPECT_TRUE(starboard::IsValid(file)); // We always try to read kTestContentsLength since the data will at most be // this long. There are test cases where the number of bytes read will be // less. - EXPECT_EQ(size, SbFileReadAll(file, result, kTestContentsLength)); - EXPECT_TRUE(SbFileClose(file)); + EXPECT_EQ(size, starboard::ReadAll(file, result, kTestContentsLength)); + EXPECT_TRUE(!close(file)); return strncmp(str, result, kTestContentsLength) == 0; } diff --git a/starboard/nplb/file_can_open_test.cc b/starboard/nplb/file_can_open_test.cc index 47bf3bb18c8f..93572606c15e 100644 --- a/starboard/nplb/file_can_open_test.cc +++ b/starboard/nplb/file_can_open_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/configuration_constants.h" @@ -70,3 +72,5 @@ TEST(SbFileCanOpenTest, ExistingStaticContentFileSucceeds) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_close_test.cc b/starboard/nplb/file_close_test.cc index 0c4c5a1c08a8..2a40d4274b36 100644 --- a/starboard/nplb/file_close_test.cc +++ b/starboard/nplb/file_close_test.cc @@ -14,6 +14,8 @@ // SbFileClose is partially tested in file_open_test.cc. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,3 +31,5 @@ TEST(SbFileCloseTest, CloseInvalidFails) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_delete_recursive_test.cc b/starboard/nplb/file_delete_recursive_test.cc index 29e8774aaa86..3ed6d0e69792 100644 --- a/starboard/nplb/file_delete_recursive_test.cc +++ b/starboard/nplb/file_delete_recursive_test.cc @@ -69,8 +69,7 @@ TEST(SbFileDeleteRecursiveTest, SunnyDayDeleteExistingPath) { EXPECT_TRUE(DirectoryExists(path.c_str())); } - SbFileError err = kSbFileOk; - SbFile file = kSbFileInvalid; + int file = -1; // Create files in our directory tree. for (size_t i = 0; i < kFileCount; ++i) { @@ -78,11 +77,10 @@ TEST(SbFileDeleteRecursiveTest, SunnyDayDeleteExistingPath) { EXPECT_FALSE(FileExists(path.c_str())); - file = SbFileOpen(path.c_str(), kSbFileCreateAlways | kSbFileWrite, NULL, - &err); + file = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); - EXPECT_EQ(kSbFileOk, err); - EXPECT_TRUE(SbFileClose(file)); + EXPECT_TRUE(file >= 0); + EXPECT_EQ(close(file), 0); EXPECT_TRUE(FileExists(path.c_str())); } @@ -110,14 +108,12 @@ TEST(SbFileDeleteRecursiveTest, RainyDayDeleteFileIgnoresPreserveRoot) { EXPECT_FALSE(FileExists(path.c_str())); - SbFileError err = kSbFileOk; - SbFile file = kSbFileInvalid; + int file = -1; - file = - SbFileOpen(path.c_str(), kSbFileCreateAlways | kSbFileWrite, NULL, &err); + file = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR); - EXPECT_EQ(kSbFileOk, err); - EXPECT_TRUE(SbFileClose(file)); + EXPECT_TRUE(file >= 0); + EXPECT_EQ(close(file), 0); EXPECT_TRUE(FileExists(path.c_str())); EXPECT_TRUE(SbFileDeleteRecursive(path.c_str(), true)); EXPECT_FALSE(FileExists(path.c_str())); diff --git a/starboard/nplb/file_delete_test.cc b/starboard/nplb/file_delete_test.cc index 92fbe199dffd..95052867700d 100644 --- a/starboard/nplb/file_delete_test.cc +++ b/starboard/nplb/file_delete_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include @@ -63,3 +65,5 @@ TEST(SbFileDeleteTest, RainyDayNonExistentFileErrors) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_flush_test.cc b/starboard/nplb/file_flush_test.cc index d17795f912b3..7b8b3143ccbd 100644 --- a/starboard/nplb/file_flush_test.cc +++ b/starboard/nplb/file_flush_test.cc @@ -14,6 +14,8 @@ // SbFileFlush is otherwise tested in SbFileWriteTest. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/nplb/file_helpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -30,3 +32,5 @@ TEST(SbFileFlushTest, InvalidFileErrors) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_get_info_test.cc b/starboard/nplb/file_get_info_test.cc index 6f531b39c8ba..2bfc5da8120a 100644 --- a/starboard/nplb/file_get_info_test.cc +++ b/starboard/nplb/file_get_info_test.cc @@ -14,6 +14,8 @@ // GetInfo is mostly tested in the course of other tests. +#if SB_API_VERSION < 17 + #include #include "starboard/common/time.h" @@ -87,3 +89,5 @@ TEST(SbFileGetInfoTest, WorksOnStaticContentFiles) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_helpers.cc b/starboard/nplb/file_helpers.cc index e1715ae44df3..5f979f995ae5 100644 --- a/starboard/nplb/file_helpers.cc +++ b/starboard/nplb/file_helpers.cc @@ -14,16 +14,18 @@ #include "starboard/nplb/file_helpers.h" +#include #include +#include #include #include #include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/configuration_constants.h" #include "starboard/directory.h" -#include "starboard/file.h" #include "starboard/system.h" #include "testing/gtest/include/gtest/gtest.h" @@ -135,10 +137,10 @@ std::string ScopedRandomFile::MakeRandomFile(int length) { return filename; } - SbFile file = SbFileOpen(filename.c_str(), kSbFileCreateOnly | kSbFileWrite, - NULL, NULL); - EXPECT_TRUE(SbFileIsValid(file)); - if (!SbFileIsValid(file)) { + int file = + open(filename.c_str(), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR); + EXPECT_TRUE(starboard::IsValid(file)); + if (!starboard::IsValid(file)) { return ""; } @@ -147,11 +149,11 @@ std::string ScopedRandomFile::MakeRandomFile(int length) { data[i] = static_cast(i & 0xFF); } - int bytes = SbFileWriteAll(file, data, length); + int bytes = starboard::WriteAll(file, data, length); EXPECT_EQ(bytes, length) << "Failed to write " << length << " bytes to " << filename; - bool result = SbFileClose(file); + bool result = !close(file); EXPECT_TRUE(result) << "Failed to close " << filename; delete[] data; return filename; diff --git a/starboard/nplb/file_helpers.h b/starboard/nplb/file_helpers.h index 881073732b6f..2d883932dcbe 100644 --- a/starboard/nplb/file_helpers.h +++ b/starboard/nplb/file_helpers.h @@ -15,6 +15,8 @@ #ifndef STARBOARD_NPLB_FILE_HELPERS_H_ #define STARBOARD_NPLB_FILE_HELPERS_H_ +#include + #include #include @@ -75,7 +77,7 @@ class ScopedRandomFile { (create == kCreate ? MakeRandomFile(size_) : MakeRandomFilePath()); } - ~ScopedRandomFile() { SbFileDelete(filename_.c_str()); } + ~ScopedRandomFile() { unlink(filename_.c_str()); } // Creates and returns a random filename (no path), but does not create the // file. diff --git a/starboard/nplb/file_mode_string_to_flags_test.cc b/starboard/nplb/file_mode_string_to_flags_test.cc index cc6c48f86870..9efdf3a2163e 100644 --- a/starboard/nplb/file_mode_string_to_flags_test.cc +++ b/starboard/nplb/file_mode_string_to_flags_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/file.h" @@ -59,3 +61,5 @@ TEST(SbFileModeStringToFlagsTest, Aah) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_open_test.cc b/starboard/nplb/file_open_test.cc index ae19dec24c1e..4a99d746c886 100644 --- a/starboard/nplb/file_open_test.cc +++ b/starboard/nplb/file_open_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include @@ -165,3 +167,5 @@ TEST(SbFileOpenTest, OpenOnlyDoesNotOpenNonExistingStaticContentFile) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_read_test.cc b/starboard/nplb/file_read_test.cc index f9aa51d9d29a..7d4d4a0a0d4e 100644 --- a/starboard/nplb/file_read_test.cc +++ b/starboard/nplb/file_read_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/file.h" @@ -294,3 +296,5 @@ TYPED_TEST(SbFileReadTest, ReadStaticContent) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_read_write_all_test.cc b/starboard/nplb/file_read_write_all_test.cc index 4871cea672a5..6dc621363818 100644 --- a/starboard/nplb/file_read_write_all_test.cc +++ b/starboard/nplb/file_read_write_all_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/nplb/file_helpers.h" #include "testing/gtest/include/gtest/gtest.h" @@ -63,3 +65,5 @@ INSTANTIATE_TEST_CASE_P( } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_seek_test.cc b/starboard/nplb/file_seek_test.cc index 95bbdd4db35d..35789796c1e0 100644 --- a/starboard/nplb/file_seek_test.cc +++ b/starboard/nplb/file_seek_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/file.h" @@ -235,3 +237,5 @@ TEST(SbFileSeekTest, FromBeginInStaticContentWorks) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_truncate_test.cc b/starboard/nplb/file_truncate_test.cc index ae2b3dee8255..6a316d2d7694 100644 --- a/starboard/nplb/file_truncate_test.cc +++ b/starboard/nplb/file_truncate_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include #include "starboard/file.h" @@ -115,3 +117,5 @@ TEST(SbFileTruncateTest, TruncateUpInSize) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/file_write_test.cc b/starboard/nplb/file_write_test.cc index 9f6d87d578ac..6493a783bc30 100644 --- a/starboard/nplb/file_write_test.cc +++ b/starboard/nplb/file_write_test.cc @@ -15,6 +15,8 @@ // Writing is partially tested by some of the file helpers that create files for // the tests to operate on. +#if SB_API_VERSION < 17 + #include #include "starboard/file.h" @@ -167,3 +169,5 @@ TYPED_TEST(SbFileWriteTest, WriteZeroBytes) { } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION < 17 diff --git a/starboard/nplb/media_can_play_mime_and_key_system_test.cc b/starboard/nplb/media_can_play_mime_and_key_system_test.cc index e2d08a9e31e1..6c2619942b4e 100644 --- a/starboard/nplb/media_can_play_mime_and_key_system_test.cc +++ b/starboard/nplb/media_can_play_mime_and_key_system_test.cc @@ -793,7 +793,11 @@ TEST(SbMediaCanPlayMimeAndKeySystem, ValidateQueriesUnderPeakCapability) { } TEST(SbMediaCanPlayMimeAndKeySystem, VerifyMaxBitrate) { +#if SB_API_VERSION >= 15 constexpr int kAv14kBitrate = 40000000; +#else + constexpr int kAv14kBitrate = 42000000; +#endif // SB_API_VERSION >= 15 const std::pair kCodecSupportQueries[] = { {// AV1 1080P SDR diff --git a/starboard/nplb/media_set_audio_write_duration_test.cc b/starboard/nplb/media_set_audio_write_duration_test.cc index 6674d4c84212..5c9d67ecc1fb 100644 --- a/starboard/nplb/media_set_audio_write_duration_test.cc +++ b/starboard/nplb/media_set_audio_write_duration_test.cc @@ -59,8 +59,13 @@ class SbMediaSetAudioWriteDurationTest } // Check if we're about to input too far beyond the current playback time. +#if SB_API_VERSION >= 15 SbPlayerInfo info; SbPlayerGetInfo(pending_decoder_status_->player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; + SbPlayerGetInfo2(pending_decoder_status_->player, &info); +#endif // SB_API_VERSION >= 15 if ((last_input_timestamp_ - info.current_media_timestamp) > kDuration) { // Postpone writing samples. return; @@ -185,18 +190,30 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteLimitedInput) { WaitForPlayerState(kSbPlayerStateInitialized); // Seek to preroll. +#if SB_API_VERSION >= 15 SbPlayerSeek(player, first_input_timestamp_, /* ticket */ 1); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, first_input_timestamp_, /* ticket */ 1); +#endif // SB_API_VERSION >= 15 WaitForPlayerState(kSbPlayerStatePresenting); // Wait until the playback time is > 0. const int64_t kMaxWaitTime = 5'000'000; // 5 seconds int64_t start_of_wait = CurrentMonotonicTime(); +#if SB_API_VERSION >= 15 SbPlayerInfo info = {}; +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info = {}; +#endif // SB_API_VERSION >= 15 while (CurrentMonotonicTime() - start_of_wait < kMaxWaitTime && info.current_media_timestamp == 0) { usleep(500'000); +#if SB_API_VERSION >= 15 SbPlayerGetInfo(player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 } EXPECT_GT(info.current_media_timestamp, 0); @@ -215,7 +232,11 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteContinuedLimitedInput) { WaitForPlayerState(kSbPlayerStateInitialized); // Seek to preroll. +#if SB_API_VERSION >= 15 SbPlayerSeek(player, first_input_timestamp_, /* ticket */ 1); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player, first_input_timestamp_, /* ticket */ 1); +#endif // SB_API_VERSION >= 15 WaitForPlayerState(kSbPlayerStatePresenting); // Wait for the player to play far enough. It may not play all the way to @@ -223,12 +244,20 @@ TEST_P(SbMediaSetAudioWriteDurationTest, WriteContinuedLimitedInput) { int64_t min_ending_playback_time = total_duration_ - kDuration; int64_t start_of_wait = CurrentMonotonicTime(); const int64_t kMaxWaitTime = total_duration_ + 5'000'000LL; +#if SB_API_VERSION >= 15 SbPlayerInfo info; SbPlayerGetInfo(player, &info); - +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info; + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 while (info.current_media_timestamp < min_ending_playback_time && (CurrentMonotonicTime() - start_of_wait) < kMaxWaitTime) { +#if SB_API_VERSION >= 15 SbPlayerGetInfo(player, &info); +#else // SB_API_VERSION >= 15 + SbPlayerGetInfo2(player, &info); +#endif // SB_API_VERSION >= 15 usleep(kSmallWaitInterval); TryToWritePendingSample(); } diff --git a/starboard/nplb/nplb_evergreen_compat_tests/storage_test.cc b/starboard/nplb/nplb_evergreen_compat_tests/storage_test.cc index 91f47b172e25..b5f03f02c99b 100644 --- a/starboard/nplb/nplb_evergreen_compat_tests/storage_test.cc +++ b/starboard/nplb/nplb_evergreen_compat_tests/storage_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include #include @@ -81,7 +82,7 @@ TEST_F(StorageTest, VerifyStorageDirectory) { ASSERT_EQ('A', buf[i]); } - ASSERT_TRUE(SbFileDelete(file_path.data())); + ASSERT_TRUE(!unlink(file_path.data())); struct stat info; ASSERT_FALSE(stat(file_path.data(), &info) == 0); } diff --git a/starboard/nplb/player_create_test.cc b/starboard/nplb/player_create_test.cc index 20d0d6a6b52e..5dd8c2567f74 100644 --- a/starboard/nplb/player_create_test.cc +++ b/starboard/nplb/player_create_test.cc @@ -334,7 +334,9 @@ TEST_F(SbPlayerTest, MultiPlayer) { kSbMediaAudioCodecMp3, kSbMediaAudioCodecFlac, kSbMediaAudioCodecPcm, +#if SB_API_VERSION >= 15 kSbMediaAudioCodecIamf, +#endif // SB_API_VERSION >= 15 }; // clang-format on @@ -353,7 +355,9 @@ TEST_F(SbPlayerTest, MultiPlayer) { case kAudioCodecs[6]: case kAudioCodecs[7]: case kAudioCodecs[8]: +#if SB_API_VERSION >= 15 case kAudioCodecs[9]: +#endif // SB_API_VERSION >= 15 break; } diff --git a/starboard/nplb/player_creation_param_helpers.cc b/starboard/nplb/player_creation_param_helpers.cc index fc41c27c443a..a9dfc3c58aba 100644 --- a/starboard/nplb/player_creation_param_helpers.cc +++ b/starboard/nplb/player_creation_param_helpers.cc @@ -92,12 +92,14 @@ AudioStreamInfo CreateAudioStreamInfo(SbMediaAudioCodec codec) { audio_stream_info.bits_per_sample = 32; break; } +#if SB_API_VERSION >= 15 case kSbMediaAudioCodecIamf: { audio_stream_info.number_of_channels = 2; audio_stream_info.samples_per_second = 48000; audio_stream_info.bits_per_sample = 32; break; } +#endif // SB_API_VERSION >= 15 } return audio_stream_info; } diff --git a/starboard/nplb/player_creation_param_helpers.h b/starboard/nplb/player_creation_param_helpers.h index a068dbfda3fc..3c607dcdbe99 100644 --- a/starboard/nplb/player_creation_param_helpers.h +++ b/starboard/nplb/player_creation_param_helpers.h @@ -50,8 +50,13 @@ struct PlayerCreationParam { creation_param->drm_system = drm_system; +#if SB_API_VERSION >= 15 audio_stream_info.ConvertTo(&creation_param->audio_stream_info); video_stream_info.ConvertTo(&creation_param->video_stream_info); +#else // SB_API_VERSION >= 15 + audio_stream_info.ConvertTo(&creation_param->audio_sample_info); + video_stream_info.ConvertTo(&creation_param->video_sample_info); +#endif // SB_API_VERSION >= 15 creation_param->output_mode = output_mode; } diff --git a/starboard/nplb/player_get_audio_configuration_test.cc b/starboard/nplb/player_get_audio_configuration_test.cc index 8a2bb8818d48..7cd5a7e5a8bc 100644 --- a/starboard/nplb/player_get_audio_configuration_test.cc +++ b/starboard/nplb/player_get_audio_configuration_test.cc @@ -19,6 +19,8 @@ #include "starboard/testing/fake_graphics_context_provider.h" #include "testing/gtest/include/gtest/gtest.h" +#if SB_API_VERSION >= 15 + bool operator==(const SbMediaAudioConfiguration& left, const SbMediaAudioConfiguration& right) { return memcmp(&left, &right, sizeof(SbMediaAudioConfiguration)) == 0; @@ -273,3 +275,5 @@ INSTANTIATE_TEST_CASE_P(SbPlayerGetAudioConfigurationTests, } // namespace } // namespace nplb } // namespace starboard + +#endif // SB_API_VERSION >= 15 diff --git a/starboard/nplb/player_get_preferred_output_mode_test.cc b/starboard/nplb/player_get_preferred_output_mode_test.cc index d38502a68e23..69e5be37b511 100644 --- a/starboard/nplb/player_get_preferred_output_mode_test.cc +++ b/starboard/nplb/player_get_preferred_output_mode_test.cc @@ -56,7 +56,9 @@ TEST(SbPlayerGetPreferredOutputModeTest, AllCodecs) { kSbMediaAudioCodecMp3, kSbMediaAudioCodecFlac, kSbMediaAudioCodecPcm, +#if SB_API_VERSION >= 15 kSbMediaAudioCodecIamf, +#endif // SB_API_VERSION >= 15 }; const SbMediaVideoCodec kVideoCodecs[] = { kSbMediaVideoCodecNone, diff --git a/starboard/nplb/player_test_fixture.cc b/starboard/nplb/player_test_fixture.cc index 30700e23cf45..6aaf93a8b958 100644 --- a/starboard/nplb/player_test_fixture.cc +++ b/starboard/nplb/player_test_fixture.cc @@ -250,7 +250,11 @@ void SbPlayerTestFixture::Seek(const int64_t time) { audio_end_of_stream_written_ = false; video_end_of_stream_written_ = false; +#if SB_API_VERSION >= 15 SbPlayerSeek(player_, time, ++ticket_); +#else // SB_API_VERSION >= 15 + SbPlayerSeek2(player_, time, ++ticket_); +#endif // SB_API_VERSION >= 15 } void SbPlayerTestFixture::Write(const GroupedSamples& grouped_samples) { @@ -345,8 +349,13 @@ void SbPlayerTestFixture::WaitForPlayerEndOfStream() { } int64_t SbPlayerTestFixture::GetCurrentMediaTime() const { +#if SB_API_VERSION >= 15 SbPlayerInfo info = {}; SbPlayerGetInfo(player_, &info); +#else // SB_API_VERSION >= 15 + SbPlayerInfo2 info = {}; + SbPlayerGetInfo2(player_, &info); +#endif // SB_API_VERSION >= 15 return info.current_media_timestamp; } diff --git a/starboard/nplb/player_test_util.cc b/starboard/nplb/player_test_util.cc index 7fa84d067dca..0c38b9b6c56a 100644 --- a/starboard/nplb/player_test_util.cc +++ b/starboard/nplb/player_test_util.cc @@ -14,10 +14,10 @@ #include "starboard/nplb/player_test_util.h" +#include #include #include "starboard/audio_sink.h" -#include "starboard/common/atomic.h" #include "starboard/common/string.h" #include "starboard/extension/enhanced_audio.h" #include "starboard/nplb/drm_helpers.h" @@ -56,8 +56,10 @@ const char* kAudioOnlyTestFiles[] = { "beneath_the_canopy_opus_5_1.dmp", "beneath_the_canopy_opus_mono.dmp", "heaac.dmp", +#if SB_API_VERSION >= 15 "iamf_base_profile_stereo_ambisonics.dmp", "iamf_simple_profile_5_1.dmp", +#endif // SB_API_VERSION >= 15 "sintel_5s_flac.dmp", "sintel_5s_mp3.dmp", "sintel_5s_pcm_s16le.dmp", @@ -79,7 +81,7 @@ void ErrorFunc(SbPlayer player, void* context, SbPlayerError error, const char* message) { - atomic_bool* error_occurred = static_cast(context); + std::atomic_bool* error_occurred = static_cast(context); error_occurred->exchange(true); } @@ -291,7 +293,9 @@ void CallSbPlayerWriteSamples( static auto const* enhanced_audio_extension = static_cast( SbSystemGetExtension(kCobaltExtensionEnhancedAudioName)); +#if SB_API_VERSION >= 15 ASSERT_FALSE(enhanced_audio_extension); +#endif // SB_API_VERSION >= 15 if (enhanced_audio_extension) { ASSERT_STREQ(enhanced_audio_extension->name, @@ -347,6 +351,7 @@ void CallSbPlayerWriteSamples( sample_infos.push_back( dmp_reader->GetPlayerSampleInfo(sample_type, start_index++)); sample_infos.back().timestamp += timestamp_offset; +#if SB_API_VERSION >= 15 if (!discarded_durations_from_front.empty()) { sample_infos.back().audio_sample_info.discarded_duration_from_front = discarded_durations_from_front[i]; @@ -355,9 +360,15 @@ void CallSbPlayerWriteSamples( sample_infos.back().audio_sample_info.discarded_duration_from_back = discarded_durations_from_back[i]; } +#endif // SB_API_VERSION >= 15 } +#if SB_API_VERSION >= 15 SbPlayerWriteSamples(player, sample_type, sample_infos.data(), number_of_samples_to_write); +#else // SB_API_VERSION >= 15 + SbPlayerWriteSample2(player, sample_type, sample_infos.data(), + number_of_samples_to_write); +#endif // SB_API_VERSION >= 15 } bool IsOutputModeSupported(SbPlayerOutputMode output_mode, @@ -392,11 +403,15 @@ bool IsOutputModeSupported(SbPlayerOutputMode output_mode, } bool IsPartialAudioSupported() { +#if SB_API_VERSION >= 15 #if SB_API_VERSION >= 16 return kHasPartialAudioFramesSupport; -#else // SB_API_VERSION >= 16 +#else return true; -#endif // SB_API_VERSION >= 16 +#endif +#else // SB_API_VERSION >= 15 + return SbSystemGetExtension(kCobaltExtensionEnhancedAudioName) != nullptr; +#endif // SB_API_VERSION >= 15 } bool IsAudioPassthroughUsed(const SbPlayerTestConfig& config) { diff --git a/starboard/nplb/posix_compliance/posix_file_can_open_test.cc b/starboard/nplb/posix_compliance/posix_file_can_open_test.cc new file mode 100644 index 000000000000..a1747ce4d626 --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_file_can_open_test.cc @@ -0,0 +1,73 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include + +#include + +#include "starboard/common/file.h" +#include "starboard/configuration_constants.h" +#include "starboard/nplb/file_helpers.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +TEST(PosixFileCanOpenTest, NonExistingFileFails) { + ScopedRandomFile random_file(ScopedRandomFile::kDontCreate); + const std::string& filename = random_file.filename(); + + bool result = starboard::FileCanOpen(filename.c_str(), O_RDONLY); + EXPECT_FALSE(result); + + result = + starboard::FileCanOpen(filename.c_str(), O_CREAT | O_EXCL | O_WRONLY); + EXPECT_FALSE(result); + + result = starboard::FileCanOpen(filename.c_str(), O_CREAT | O_RDWR); + EXPECT_FALSE(result); +} + +TEST(PosixFileCanOpenTest, ExistingFileSucceeds) { + ScopedRandomFile random_file; + const std::string& filename = random_file.filename(); + + bool result = starboard::FileCanOpen(filename.c_str(), O_RDONLY); + EXPECT_TRUE(result); + + result = + starboard::FileCanOpen(filename.c_str(), O_CREAT | O_EXCL | O_WRONLY); + EXPECT_TRUE(result); + + result = starboard::FileCanOpen(filename.c_str(), O_CREAT | O_RDWR); + EXPECT_TRUE(result); +} + +TEST(PosixFileCanOpenTest, NonExistingStaticContentFileFails) { + std::string directory_path = GetFileTestsDataDir(); + std::string missing_file = directory_path + kSbFileSepChar + "missing_file"; + EXPECT_FALSE(starboard::FileCanOpen(missing_file.c_str(), O_RDONLY)); +} + +TEST(PosixFileCanOpenTest, ExistingStaticContentFileSucceeds) { + for (auto path : GetFileTestsFilePaths()) { + EXPECT_TRUE(starboard::FileCanOpen(path.c_str(), O_RDONLY)) + << "Can't open: " << path; + } +} + +} // namespace +} // namespace nplb +} // namespace starboard diff --git a/starboard/nplb/posix_compliance/posix_file_mode_string_to_flags_test.cc b/starboard/nplb/posix_compliance/posix_file_mode_string_to_flags_test.cc new file mode 100644 index 000000000000..66349e21c7bd --- /dev/null +++ b/starboard/nplb/posix_compliance/posix_file_mode_string_to_flags_test.cc @@ -0,0 +1,58 @@ +// Copyright 2024 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#if SB_API_VERSION >= 16 + +#include + +#include + +#include "starboard/common/file_wrapper.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace starboard { +namespace nplb { +namespace { + +TEST(PosixFileModeStringToFlagsTest, Empties) { + EXPECT_EQ(0, FileModeStringToFlags(NULL)); + EXPECT_EQ(0, FileModeStringToFlags("")); +} + +TEST(PosixFileModeStringToFlagsTest, ReadMode) { + EXPECT_EQ(O_RDONLY, FileModeStringToFlags("r")); + EXPECT_EQ(O_RDWR, FileModeStringToFlags("r+")); + EXPECT_EQ(O_RDWR, FileModeStringToFlags("r+b")); + EXPECT_EQ(O_RDWR, FileModeStringToFlags("rb+")); +} + +TEST(PosixFileModeStringToFlagsTest, WriteMode) { + EXPECT_EQ(O_CREAT | O_TRUNC | O_WRONLY, FileModeStringToFlags("w")); + EXPECT_EQ(O_CREAT | O_TRUNC | O_RDWR, FileModeStringToFlags("w+")); + EXPECT_EQ(O_CREAT | O_TRUNC | O_RDWR, FileModeStringToFlags("w+b")); + EXPECT_EQ(O_CREAT | O_TRUNC | O_RDWR, FileModeStringToFlags("wb+")); +} + +TEST(PosixFileModeStringToFlagsTest, AppendMode) { + EXPECT_EQ(O_CREAT | O_WRONLY, FileModeStringToFlags("a")); + EXPECT_EQ(O_CREAT | O_RDWR, FileModeStringToFlags("a+")); + EXPECT_EQ(O_CREAT | O_RDWR, FileModeStringToFlags("a+b")); + EXPECT_EQ(O_CREAT | O_RDWR, FileModeStringToFlags("ab+")); +} + +} // namespace +} // namespace nplb +} // namespace starboard + +#endif // SB_API_VERSION >= 16 diff --git a/starboard/nplb/system_clear_last_error_test.cc b/starboard/nplb/system_clear_last_error_test.cc index 1755799a8447..699656826d5e 100644 --- a/starboard/nplb/system_clear_last_error_test.cc +++ b/starboard/nplb/system_clear_last_error_test.cc @@ -12,7 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "starboard/file.h" +#include + #include "starboard/nplb/file_helpers.h" #include "starboard/system.h" #include "testing/gtest/include/gtest/gtest.h" @@ -24,8 +25,7 @@ namespace { TEST(SbSystemClearLastErrorTest, SunnyDay) { // Opening a non-existent file should generate an error on all platforms. ScopedRandomFile random_file(ScopedRandomFile::kDontCreate); - SbFile file = SbFileOpen(random_file.filename().c_str(), - kSbFileOpenOnly | kSbFileRead, NULL, NULL); + int file = open(random_file.filename().c_str(), O_RDONLY, S_IRUSR | S_IWUSR); EXPECT_NE(0, SbSystemGetLastError()); SbSystemClearLastError(); diff --git a/starboard/nplb/system_get_error_string_test.cc b/starboard/nplb/system_get_error_string_test.cc index 1fb6aa5d28e6..04fa50d84803 100644 --- a/starboard/nplb/system_get_error_string_test.cc +++ b/starboard/nplb/system_get_error_string_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "starboard/common/string.h" #include "starboard/file.h" #include "starboard/nplb/file_helpers.h" @@ -25,8 +27,7 @@ namespace { TEST(SbSystemGetErrorStringTest, SunnyDay) { // Opening a non-existent file should generate an error on all platforms. ScopedRandomFile random_file(ScopedRandomFile::kDontCreate); - SbFile file = SbFileOpen(random_file.filename().c_str(), - kSbFileOpenOnly | kSbFileRead, NULL, NULL); + int file = open(random_file.filename().c_str(), O_RDONLY, S_IRUSR | S_IWUSR); SbSystemError error = SbSystemGetLastError(); EXPECT_NE(0, error); diff --git a/starboard/nplb/system_get_last_error_test.cc b/starboard/nplb/system_get_last_error_test.cc index d6f43231f67c..f001a9d23993 100644 --- a/starboard/nplb/system_get_last_error_test.cc +++ b/starboard/nplb/system_get_last_error_test.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include + #include "starboard/file.h" #include "starboard/nplb/file_helpers.h" #include "starboard/system.h" @@ -24,8 +26,7 @@ namespace { TEST(SbSystemGetLastErrorTest, SunnyDay) { // Opening a non-existent file should generate an error on all platforms. ScopedRandomFile random_file(ScopedRandomFile::kDontCreate); - SbFile file = SbFileOpen(random_file.filename().c_str(), - kSbFileOpenOnly | kSbFileRead, NULL, NULL); + int file = open(random_file.filename().c_str(), O_RDONLY, S_IRUSR | S_IWUSR); SbSystemError error = SbSystemGetLastError(); EXPECT_NE(0, error); diff --git a/starboard/nplb/system_get_path_test.cc b/starboard/nplb/system_get_path_test.cc index 350a2d4c52a3..002d515e89fc 100644 --- a/starboard/nplb/system_get_path_test.cc +++ b/starboard/nplb/system_get_path_test.cc @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -132,7 +133,8 @@ TEST(SbSystemGetPathTest, CanCreateAndRemoveDirectoryInCache) { std::string sub_path = kSbFileSepString + ScopedRandomFile::MakeRandomFilename(); EXPECT_GT(starboard::strlcat(path.data(), sub_path.c_str(), kPathSize), 0); - EXPECT_TRUE(SbFileDelete(path.data())); + // rmdir return -1 when directory does not exist. + EXPECT_TRUE(rmdir(path.data()) == 0 || !DirectoryExists(path.data())); EXPECT_FALSE(FileExists(path.data())); // Create the directory and confirm it exists and can be opened. @@ -146,7 +148,7 @@ TEST(SbSystemGetPathTest, CanCreateAndRemoveDirectoryInCache) { // Lastly, close and delete the directory. EXPECT_TRUE(closedir(directory) == 0); - EXPECT_TRUE(SbFileDelete(path.data())); + EXPECT_TRUE(rmdir(path.data()) == 0); EXPECT_FALSE(FileExists(path.data())); } } @@ -165,7 +167,8 @@ TEST(SbSystemGetPathTest, CanWriteAndReadCache) { std::string sub_path = kSbFileSepString + ScopedRandomFile::MakeRandomFilename(); EXPECT_GT(starboard::strlcat(path.data(), sub_path.c_str(), kPathSize), 0); - EXPECT_TRUE(SbFileDelete(path.data())); + // unlink return -1 when directory does not exist. + EXPECT_TRUE(unlink(path.data()) == 0 || !FileExists(path.data())); EXPECT_FALSE(FileExists(path.data())); // Write to the file and check that we can read from it. @@ -192,7 +195,7 @@ TEST(SbSystemGetPathTest, CanWriteAndReadCache) { EXPECT_EQ(content_read, content_to_write); // Lastly, delete the file. - EXPECT_TRUE(SbFileDelete(path.data())); + EXPECT_TRUE(unlink(path.data()) == 0); EXPECT_FALSE(FileExists(path.data())); } } diff --git a/starboard/nplb/system_get_property_test.cc b/starboard/nplb/system_get_property_test.cc index e938899db7b1..a50f0821f7a4 100644 --- a/starboard/nplb/system_get_property_test.cc +++ b/starboard/nplb/system_get_property_test.cc @@ -28,6 +28,22 @@ namespace { // Size of appropriate value buffer. const size_t kValueSize = 1024; +#if SB_API_VERSION < 15 +bool IsCEDevice(SbSystemDeviceType device_type) { + switch (device_type) { + case kSbSystemDeviceTypeBlueRayDiskPlayer: + case kSbSystemDeviceTypeGameConsole: + case kSbSystemDeviceTypeOverTheTopBox: + case kSbSystemDeviceTypeSetTopBox: + case kSbSystemDeviceTypeTV: + return true; + case kSbSystemDeviceTypeDesktopPC: + case kSbSystemDeviceTypeUnknown: + default: + return false; + } +} +#endif bool IsCEDevice(std::string device_type) { if (device_type == kSystemDeviceTypeBlueRayDiskPlayer || device_type == kSystemDeviceTypeGameConsole || @@ -81,6 +97,17 @@ TEST(SbSystemGetPropertyTest, ReturnsRequired) { BasicTest(kSbSystemPropertyFirmwareVersion, false, true, __LINE__); BasicTest(kSbSystemPropertySystemIntegratorName, false, true, __LINE__); BasicTest(kSbSystemPropertySpeechApiKey, false, true, __LINE__); +#if SB_API_VERSION < 15 + if (IsCEDevice(SbSystemGetDeviceType())) { + BasicTest(kSbSystemPropertyBrandName, true, true, __LINE__); + BasicTest(kSbSystemPropertyModelName, true, true, __LINE__); + BasicTest(kSbSystemPropertyModelYear, false, true, __LINE__); + } else { + BasicTest(kSbSystemPropertyBrandName, false, true, __LINE__); + BasicTest(kSbSystemPropertyModelName, false, true, __LINE__); + BasicTest(kSbSystemPropertyModelYear, false, true, __LINE__); + } +#else const size_t kSystemPropertyMaxLength = 1024; char value[kSystemPropertyMaxLength]; bool result; @@ -95,6 +122,7 @@ TEST(SbSystemGetPropertyTest, ReturnsRequired) { BasicTest(kSbSystemPropertyModelName, false, true, __LINE__); BasicTest(kSbSystemPropertyModelYear, false, true, __LINE__); } +#endif } TEST(SbSystemGetPropertyTest, FailsGracefullyZeroBufferLength) { @@ -160,6 +188,7 @@ TEST(SbSystemGetPropertyTest, SpeechApiKeyNotLeaked) { } } +#if SB_API_VERSION >= 15 TEST(SbSystemGetPropertyTest, DeviceTypeAllowed) { std::string device_type = GetSystemPropertyString(kSbSystemPropertyDeviceType); @@ -190,6 +219,7 @@ TEST(SbSystemGetPropertyTest, DeviceTypeAllowed) { } ASSERT_TRUE(result); } +#endif } // namespace } // namespace nplb diff --git a/starboard/nplb/thread_sampler_test.cc b/starboard/nplb/thread_sampler_test.cc index 0693e9858baa..65f90fc37dbc 100644 --- a/starboard/nplb/thread_sampler_test.cc +++ b/starboard/nplb/thread_sampler_test.cc @@ -14,8 +14,8 @@ #include #include +#include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/time.h" @@ -41,7 +41,7 @@ class CountingThread : public posix::AbstractTestThread { void Run() override { while (!stop_.load()) { - counter_.increment(); + ++counter_; usleep(1000); } } @@ -65,8 +65,8 @@ class CountingThread : public posix::AbstractTestThread { } private: - atomic_bool stop_; - atomic_int32_t counter_; + std::atomic_bool stop_{false}; + std::atomic_int counter_{0}; }; TEST(ThreadSamplerTest, RainyDayCreateSamplerInvalidThread) { diff --git a/starboard/nplb/thread_test.cc b/starboard/nplb/thread_test.cc index b2cb4e79b9e9..861178fbe5ec 100644 --- a/starboard/nplb/thread_test.cc +++ b/starboard/nplb/thread_test.cc @@ -14,9 +14,9 @@ #include +#include #include -#include "starboard/common/atomic.h" #include "starboard/common/semaphore.h" #include "starboard/common/thread.h" #include "testing/gtest/include/gtest/gtest.h" @@ -27,14 +27,14 @@ namespace { class TestRunThread : public Thread { public: - TestRunThread() : Thread("TestThread"), finished_(false) {} + TestRunThread() : Thread("TestThread") {} void Run() override { while (!WaitForJoin(1000)) { } finished_.store(true); } - atomic_bool finished_; + std::atomic_bool finished_{false}; }; // Tests the expectation that a thread subclass will have the expected diff --git a/starboard/player.h b/starboard/player.h index b1afa9d5710e..340a89bca86e 100644 --- a/starboard/player.h +++ b/starboard/player.h @@ -105,6 +105,7 @@ typedef struct SbPlayerCreationParam { // encrypted portions. SbDrmSystem drm_system; +#if SB_API_VERSION >= 15 // Contains a populated SbMediaAudioStreamInfo if |audio_stream_info.codec| // isn't |kSbMediaAudioCodecNone|. When |audio_stream_info.codec| is // |kSbMediaAudioCodecNone|, the video doesn't have an audio track. @@ -113,6 +114,16 @@ typedef struct SbPlayerCreationParam { // isn't |kSbMediaVideoCodecNone|. When |video_stream_info.codec| is // |kSbMediaVideoCodecNone|, the video is audio only. SbMediaVideoStreamInfo video_stream_info; +#else // SB_API_VERSION >= 15 + // Contains a populated SbMediaAudioSampleInfo if |audio_sample_info.codec| + // isn't |kSbMediaAudioCodecNone|. When |audio_sample_info.codec| is + // |kSbMediaAudioCodecNone|, the video doesn't have an audio track. + SbMediaAudioSampleInfo audio_sample_info; + // Contains a populated SbMediaVideoSampleInfo if |video_sample_info.codec| + // isn't |kSbMediaVideoCodecNone|. When |video_sample_info.codec| is + // |kSbMediaVideoCodecNone|, the video is audio only. + SbMediaVideoSampleInfo video_sample_info; +#endif // SB_API_VERSION >= 15 // Selects how the decoded video frames will be output. For example, // |kSbPlayerOutputModePunchOut| indicates that the decoded video frames will @@ -177,7 +188,11 @@ typedef struct SbPlayerSampleInfo { } SbPlayerSampleInfo; // Information about the current media playback state. +#if SB_API_VERSION >= 15 typedef struct SbPlayerInfo { +#else // SB_API_VERSION >= 15 +typedef struct SbPlayerInfo2 { +#endif // SB_API_VERSION >= 15 // The position of the playback head, as precisely as possible, in // microseconds. int64_t current_media_timestamp; @@ -222,7 +237,11 @@ typedef struct SbPlayerInfo { // is played in a slower than normal speed. Negative speeds are not // supported. double playback_rate; +#if SB_API_VERSION >= 15 } SbPlayerInfo; +#else // SB_API_VERSION >= 15 +} SbPlayerInfo2; +#endif // SB_API_VERSION >= 15 // An opaque handle to an implementation-private structure representing a // player. @@ -287,6 +306,8 @@ typedef void (*SbPlayerDeallocateSampleFunc)(SbPlayer player, // Well-defined value for an invalid player. #define kSbPlayerInvalid ((SbPlayer)NULL) +#if SB_API_VERSION >= 15 + // The audio write duration when all the audio connectors are local. #define kSbPlayerWriteDurationLocal (1000000 / 2) // 0.5 seconds @@ -294,6 +315,8 @@ typedef void (*SbPlayerDeallocateSampleFunc)(SbPlayer player, // remote. #define kSbPlayerWriteDurationRemote (1000000 * 10) // 10 seconds +#endif // SB_API_VERSION >= 15 + // Returns whether the given player handle is valid. static inline bool SbPlayerIsValid(SbPlayer player) { return player != kSbPlayerInvalid; @@ -466,9 +489,15 @@ SB_EXPORT void SbPlayerDestroy(SbPlayer player); // when SbPlayerSeek was called. To be very specific, once SbPlayerSeek has // been called with ticket X, a client should ignore all // |SbPlayerDecoderStatusFunc| calls that do not pass in ticket X. +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket); +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerSeek2(SbPlayer player, + int64_t seek_to_timestamp, + int ticket); +#endif // SB_API_VERSION >= 15 // Writes samples of the given media type to |player|'s input stream. The // lifetime of |sample_infos|, and the members of its elements like |buffer|, @@ -496,7 +525,11 @@ SB_EXPORT void SbPlayerSeek(SbPlayer player, // |number_of_sample_infos|: Specify the number of samples contained inside // |sample_infos|. It has to be at least one, and at most the return value // of SbPlayerGetMaximumNumberOfSamplesPerWrite(). +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos); @@ -592,7 +625,12 @@ SB_EXPORT void SbPlayerSetVolume(SbPlayer player, double volume); // |kSbPlayerInvalid|. // // |out_player_info|: The information retrieved for the player. +#if SB_API_VERSION >= 15 SB_EXPORT void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info); +#else // SB_API_VERSION >= 15 +SB_EXPORT void SbPlayerGetInfo2(SbPlayer player, + SbPlayerInfo2* out_player_info2); +#endif // SB_API_VERSION >= 15 // Given a player created with the kSbPlayerOutputModeDecodeToTexture // output mode, it will return a SbDecodeTarget representing the current frame @@ -658,10 +696,12 @@ SB_EXPORT SbDecodeTarget SbPlayerGetCurrentFrame(SbPlayer player); // // |out_audio_configuration|: The information about the audio output, refer to // |SbMediaAudioConfiguration| for more details. Must not be NULL. +#if SB_API_VERSION >= 15 SB_EXPORT bool SbPlayerGetAudioConfiguration( SbPlayer player, int index, SbMediaAudioConfiguration* out_audio_configuration); +#endif // SB_API_VERSION >= 15 #ifdef __cplusplus } // extern "C" diff --git a/starboard/raspi/shared/BUILD.gn b/starboard/raspi/shared/BUILD.gn index 9f1da538920e..fcfc835ded38 100644 --- a/starboard/raspi/shared/BUILD.gn +++ b/starboard/raspi/shared/BUILD.gn @@ -65,6 +65,7 @@ static_library("starboard_platform_sources") { "//starboard/raspi/shared/open_max/video_decoder.cc", "//starboard/raspi/shared/open_max/video_decoder.h", "//starboard/raspi/shared/player_components_factory.cc", + "//starboard/raspi/shared/system_get_device_type.cc", "//starboard/raspi/shared/system_get_property.cc", "//starboard/raspi/shared/system_gles2.cc", "//starboard/raspi/shared/thread_create_priority.cc", diff --git a/starboard/raspi/shared/application_dispmanx.h b/starboard/raspi/shared/application_dispmanx.h index ecd088d7b6c6..c36eafd79825 100644 --- a/starboard/raspi/shared/application_dispmanx.h +++ b/starboard/raspi/shared/application_dispmanx.h @@ -34,8 +34,12 @@ namespace shared { class ApplicationDispmanx : public ::starboard::shared::starboard::QueueApplication { public: +#if SB_API_VERSION >= 15 explicit ApplicationDispmanx(SbEventHandleCallback sb_event_handle_callback) : window_(kSbWindowInvalid), QueueApplication(sb_event_handle_callback) {} +#else + ApplicationDispmanx() : window_(kSbWindowInvalid) {} +#endif // SB_API_VERSION >= 15 ~ApplicationDispmanx() override {} static ApplicationDispmanx* Get() { diff --git a/starboard/raspi/shared/main.cc b/starboard/raspi/shared/main.cc index c62759549277..45575c3164da 100644 --- a/starboard/raspi/shared/main.cc +++ b/starboard/raspi/shared/main.cc @@ -53,7 +53,12 @@ int main(int argc, char** argv) { third_party::crashpad::wrapper::InstallCrashpadHandler(ca_certificates_path); #endif // SB_IS(EVERGREEN_COMPATIBLE) +#if SB_API_VERSION >= 15 int result = SbRunStarboardMain(argc, argv, SbEventHandle); +#else + starboard::raspi::shared::ApplicationDispmanx application; + int result = application.Run(argc, argv); +#endif // SB_API_VERSION >= 15 starboard::shared::signal::UninstallSuspendSignalHandlers(); starboard::shared::signal::UninstallDebugSignalHandlers(); starboard::shared::signal::UninstallCrashSignalHandlers(); diff --git a/starboard/raspi/shared/run_starboard_main.cc b/starboard/raspi/shared/run_starboard_main.cc index d5f97c9511c0..9e957afcb394 100644 --- a/starboard/raspi/shared/run_starboard_main.cc +++ b/starboard/raspi/shared/run_starboard_main.cc @@ -15,8 +15,10 @@ #include "starboard/event.h" #include "starboard/raspi/shared/application_dispmanx.h" +#if SB_API_VERSION >= 15 int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { starboard::raspi::shared::ApplicationDispmanx application(callback); int result = application.Run(argc, argv); return result; } +#endif // SB_API_VERSION >= 15 diff --git a/starboard/raspi/shared/system_get_device_type.cc b/starboard/raspi/shared/system_get_device_type.cc new file mode 100644 index 000000000000..a3e78d207d19 --- /dev/null +++ b/starboard/raspi/shared/system_get_device_type.cc @@ -0,0 +1,23 @@ +// Copyright 2020 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + return kSbSystemDeviceTypeUnknown; +} + +#endif diff --git a/starboard/raspi/shared/system_get_property.cc b/starboard/raspi/shared/system_get_property.cc index 6208dee8bb5c..72cc9cce098f 100644 --- a/starboard/raspi/shared/system_get_property.cc +++ b/starboard/raspi/shared/system_get_property.cc @@ -163,9 +163,11 @@ bool SbSystemGetProperty(SbSystemPropertyId property_id, return CopyStringAndTestIfSuccess(out_value, value_length, "X11; Linux armv7l"); } +#if SB_API_VERSION >= 15 case kSbSystemPropertyDeviceType: return CopyStringAndTestIfSuccess(out_value, value_length, starboard::kSystemDeviceTypeUnknown); +#endif default: SB_DLOG(WARNING) << __FUNCTION__ diff --git a/starboard/shared/enhanced_audio/enhanced_audio.cc b/starboard/shared/enhanced_audio/enhanced_audio.cc new file mode 100644 index 000000000000..e12190872583 --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.cc @@ -0,0 +1,46 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/shared/enhanced_audio/enhanced_audio.h" + +#include "starboard/common/log.h" +#include "starboard/extension/enhanced_audio.h" +#include "starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h" + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +#if SB_API_VERSION < 15 + +namespace { + +const CobaltExtensionEnhancedAudioApi kEnhancedAudioApi = { + kCobaltExtensionEnhancedAudioName, + 1, + &EnhancedAudioPlayerWriteSamples, +}; + +} // namespace + +const void* GetEnhancedAudioApi() { + SB_LOG(INFO) << "EnhancedAudio extension enabled."; + return &kEnhancedAudioApi; +} + +#endif // SB_API_VERSION < 15 + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard diff --git a/starboard/shared/enhanced_audio/enhanced_audio.gni b/starboard/shared/enhanced_audio/enhanced_audio.gni new file mode 100644 index 000000000000..03588b8ce57b --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.gni @@ -0,0 +1,21 @@ +# Copyright 2023 The Cobalt Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +enhanced_audio_sources = [ + "//starboard/shared/enhanced_audio/enhanced_audio.cc", + "//starboard/shared/enhanced_audio/enhanced_audio.h", + "//starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc", + "//starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h", + "//starboard/shared/enhanced_audio/player_write_samples_checked.cc", +] diff --git a/starboard/shared/enhanced_audio/enhanced_audio.h b/starboard/shared/enhanced_audio/enhanced_audio.h new file mode 100644 index 000000000000..19f0729a3b2f --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio.h @@ -0,0 +1,28 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ +#define STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +const void* GetEnhancedAudioApi(); + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_H_ diff --git a/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc new file mode 100644 index 000000000000..351e19e3489e --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.cc @@ -0,0 +1,59 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h" + +#include "starboard/common/log.h" +#include "starboard/shared/starboard/player/player_internal.h" + +#if SB_API_VERSION < 15 + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +void EnhancedAudioPlayerWriteSamples( + SbPlayer player, + SbMediaType sample_type, + const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos, + int number_of_sample_infos) { + if (!SbPlayerIsValid(player)) { + SB_LOG(WARNING) << "player is invalid."; + return; + } + if (!sample_infos) { + SB_LOG(WARNING) << "sample_infos is null."; + return; + } + if (number_of_sample_infos < 1) { + SB_LOG(WARNING) << "number_of_sample_infos is " << number_of_sample_infos + << ", which should be greater than or equal to 1"; + return; + } + auto max_samples_per_write = + SbPlayerGetMaximumNumberOfSamplesPerWrite(player, sample_type); + if (number_of_sample_infos > max_samples_per_write) { + SB_LOG(WARNING) << "number_of_sample_infos is " << number_of_sample_infos + << ", which should be less than or equal to " + << max_samples_per_write; + } + + player->WriteSamples(sample_infos, number_of_sample_infos); +} + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // SB_API_VERSION < 15 diff --git a/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h new file mode 100644 index 000000000000..2f9e8e324aa2 --- /dev/null +++ b/starboard/shared/enhanced_audio/enhanced_audio_player_write_samples.h @@ -0,0 +1,41 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ +#define STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ + +#include "starboard/extension/enhanced_audio.h" + +#include "starboard/media.h" +#include "starboard/player.h" + +#if SB_API_VERSION < 15 + +namespace starboard { +namespace shared { +namespace enhanced_audio { + +void EnhancedAudioPlayerWriteSamples( + SbPlayer player, + SbMediaType sample_type, + const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos, + int number_of_sample_infos); + +} // namespace enhanced_audio +} // namespace shared +} // namespace starboard + +#endif // SB_API_VERSION < 15 + +#endif // STARBOARD_SHARED_ENHANCED_AUDIO_ENHANCED_AUDIO_PLAYER_WRITE_SAMPLES_H_ diff --git a/starboard/shared/enhanced_audio/player_write_samples_checked.cc b/starboard/shared/enhanced_audio/player_write_samples_checked.cc new file mode 100644 index 000000000000..275c0b05ceac --- /dev/null +++ b/starboard/shared/enhanced_audio/player_write_samples_checked.cc @@ -0,0 +1,31 @@ +// Copyright 2023 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/player.h" + +#include "starboard/common/log.h" + +// Special implementation of `SbPlayerWriteSample2()` for EnhancedAudio, where +// all sample writes should use the `PlayerWriteSamples()` function provided by +// the EnhancedAudio extension. +#if SB_API_VERSION < 15 + +void SbPlayerWriteSample2(SbPlayer player, + SbMediaType sample_type, + const SbPlayerSampleInfo* sample_infos, + int number_of_sample_infos) { + SB_NOTREACHED(); +} + +#endif // SB_API_VERSION < 15 diff --git a/starboard/shared/linux/system_get_random_data.cc b/starboard/shared/linux/system_get_random_data.cc index 94d22a61cea2..5bdbac84dc17 100644 --- a/starboard/shared/linux/system_get_random_data.cc +++ b/starboard/shared/linux/system_get_random_data.cc @@ -16,11 +16,13 @@ #include "starboard/system.h" +#include #include +#include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" -#include "starboard/file.h" namespace { @@ -29,17 +31,16 @@ namespace { class URandomFile { public: URandomFile() { - file_ = - SbFileOpen("/dev/urandom", kSbFileOpenOnly | kSbFileRead, NULL, NULL); - SB_DCHECK(SbFileIsValid(file_)) << "Cannot open /dev/urandom"; + file_ = open("/dev/urandom", O_RDONLY, S_IRUSR | S_IWUSR); + SB_DCHECK(starboard::IsValid(file_)) << "Cannot open /dev/urandom"; } - ~URandomFile() { SbFileClose(file_); } + ~URandomFile() { close(file_); } - SbFile file() const { return file_; } + int file() const { return file_; } private: - SbFile file_; + int file_; }; // A file that will produce any number of very random bytes. @@ -63,12 +64,12 @@ void SbSystemGetRandomData(void* out_buffer, int buffer_size) { int once_result = pthread_once(&g_urandom_file_once, &InitializeRandom); SB_DCHECK(once_result == 0); - SbFile file = g_urandom_file->file(); + int file = g_urandom_file->file(); do { // This is unsynchronized access to the File that could happen from multiple // threads. It doesn't appear that there is any locking in the Chromium // POSIX implementation that is very similar. - int result = SbFileRead(file, buffer, remaining); + int result = read(file, buffer, remaining); if (result <= 0) break; diff --git a/starboard/shared/posix/file_atomic_replace.cc b/starboard/shared/posix/file_atomic_replace.cc index ddec1db37c28..60e696876ccb 100644 --- a/starboard/shared/posix/file_atomic_replace.cc +++ b/starboard/shared/posix/file_atomic_replace.cc @@ -15,6 +15,7 @@ #include "starboard/file.h" #include +#include #include #include @@ -48,7 +49,7 @@ bool SbFileAtomicReplace(const char* path, temp_path.data(), data, data_size)) { return false; } - if (file_exists && !SbFileDelete(path)) { + if (file_exists && unlink(path)) { return false; } if (rename(temp_path.data(), path) != 0) { diff --git a/starboard/shared/posix/file_can_open.cc b/starboard/shared/posix/file_can_open.cc index d0514d78e41d..896e5faf8b56 100644 --- a/starboard/shared/posix/file_can_open.cc +++ b/starboard/shared/posix/file_can_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_can_open.h" @@ -19,3 +21,5 @@ bool SbFileCanOpen(const char* path, int flags) { return ::starboard::shared::posix::impl::FileCanOpen(path, flags); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_close.cc b/starboard/shared/posix/file_close.cc index ebda5137605b..f9a6f5d638e6 100644 --- a/starboard/shared/posix/file_close.cc +++ b/starboard/shared/posix/file_close.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_close.h" @@ -19,3 +21,5 @@ bool SbFileClose(SbFile file) { return ::starboard::shared::posix::impl::FileClose(file); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_delete.cc b/starboard/shared/posix/file_delete.cc index 7830cebc5f88..3ad7ea095407 100644 --- a/starboard/shared/posix/file_delete.cc +++ b/starboard/shared/posix/file_delete.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_delete.h" @@ -19,3 +21,5 @@ bool SbFileDelete(const char* path) { return ::starboard::shared::posix::impl::FileDelete(path); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_exists.cc b/starboard/shared/posix/file_exists.cc index b418a4692d9b..97774b07573d 100644 --- a/starboard/shared/posix/file_exists.cc +++ b/starboard/shared/posix/file_exists.cc @@ -21,4 +21,5 @@ bool SbFileExists(const char* path) { return ::starboard::shared::posix::impl::FileExists(path); } -#endif + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/posix/file_flush.cc b/starboard/shared/posix/file_flush.cc index e62aeb51db64..3f1a4c3c9751 100644 --- a/starboard/shared/posix/file_flush.cc +++ b/starboard/shared/posix/file_flush.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_flush.h" @@ -19,3 +21,5 @@ bool SbFileFlush(SbFile file) { return ::starboard::shared::posix::impl::FileFlush(file); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_get_info.cc b/starboard/shared/posix/file_get_info.cc index 163462bc3175..2443587bbce9 100644 --- a/starboard/shared/posix/file_get_info.cc +++ b/starboard/shared/posix/file_get_info.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_get_info.h" @@ -19,3 +21,5 @@ bool SbFileGetInfo(SbFile file, SbFileInfo* out_info) { return ::starboard::shared::posix::impl::FileGetInfo(file, out_info); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_open.cc b/starboard/shared/posix/file_open.cc index b8d76cf2017f..56675c63fd7a 100644 --- a/starboard/shared/posix/file_open.cc +++ b/starboard/shared/posix/file_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_open.h" @@ -23,3 +25,5 @@ SbFile SbFileOpen(const char* path, return ::starboard::shared::posix::impl::FileOpen(path, flags, out_created, out_error); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_read.cc b/starboard/shared/posix/file_read.cc index 33d6debe31e4..3721a8b9b500 100644 --- a/starboard/shared/posix/file_read.cc +++ b/starboard/shared/posix/file_read.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_read.h" @@ -19,3 +21,5 @@ int SbFileRead(SbFile file, char* data, int size) { return ::starboard::shared::posix::impl::FileRead(file, data, size); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_seek.cc b/starboard/shared/posix/file_seek.cc index 4ece7e8f0712..ba6ba4ab47b9 100644 --- a/starboard/shared/posix/file_seek.cc +++ b/starboard/shared/posix/file_seek.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_seek.h" @@ -19,3 +21,5 @@ int64_t SbFileSeek(SbFile file, SbFileWhence whence, int64_t offset) { return ::starboard::shared::posix::impl::FileSeek(file, whence, offset); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_truncate.cc b/starboard/shared/posix/file_truncate.cc index 603dd0110fa7..f119fb3d0f4d 100644 --- a/starboard/shared/posix/file_truncate.cc +++ b/starboard/shared/posix/file_truncate.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_truncate.h" @@ -19,3 +21,5 @@ bool SbFileTruncate(SbFile file, int64_t length) { return ::starboard::shared::posix::impl::FileTruncate(file, length); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/file_write.cc b/starboard/shared/posix/file_write.cc index 7b0af3dec16d..118d183de2b6 100644 --- a/starboard/shared/posix/file_write.cc +++ b/starboard/shared/posix/file_write.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/shared/posix/file_internal.h" #include "starboard/shared/posix/impl/file_write.h" @@ -19,3 +21,5 @@ int SbFileWrite(SbFile file, const char* data, int size) { return ::starboard::shared::posix::impl::FileWrite(file, data, size); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/posix/storage_write_record.cc b/starboard/shared/posix/storage_write_record.cc index 7a23c6621490..ffae1d79c5ca 100644 --- a/starboard/shared/posix/storage_write_record.cc +++ b/starboard/shared/posix/storage_write_record.cc @@ -14,13 +14,15 @@ #include "starboard/common/storage.h" +#include + #include #include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/common/string.h" #include "starboard/configuration_constants.h" -#include "starboard/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" const char kTempFileSuffix[] = ".temp"; @@ -44,25 +46,23 @@ bool SbStorageWriteRecord(SbStorageRecord record, kSbFileMaxPath); starboard::strlcat(temp_file_path.data(), kTempFileSuffix, kSbFileMaxPath); - SbFileError error; - SbFile temp_file = SbFileOpen( - temp_file_path.data(), kSbFileCreateAlways | kSbFileWrite | kSbFileRead, - NULL, &error); - if (error != kSbFileOk) { + int temp_file = open(temp_file_path.data(), O_CREAT | O_TRUNC | O_RDWR, + S_IRUSR | S_IWUSR); + if (!starboard::IsValid(temp_file)) { return false; } - SbFileTruncate(temp_file, 0); + ftruncate(temp_file, 0); const char* source = data; int64_t to_write = data_size; while (to_write > 0) { int to_write_max = static_cast(std::min(to_write, static_cast(kSbInt32Max))); - int bytes_written = SbFileWrite(temp_file, source, to_write_max); + int bytes_written = write(temp_file, source, to_write_max); if (bytes_written < 0) { - SbFileClose(temp_file); - SbFileDelete(temp_file_path.data()); + close(temp_file); + unlink(temp_file_path.data()); return false; } @@ -70,24 +70,24 @@ bool SbStorageWriteRecord(SbStorageRecord record, to_write -= bytes_written; } - SbFileFlush(temp_file); + fsync(temp_file); - if (SbFileIsValid(record->file) && !SbFileClose(record->file)) { - SbFileClose(temp_file); - SbFileDelete(temp_file_path.data()); + if (starboard::IsValid(record->file) && (close(record->file) < 0)) { + close(temp_file); + unlink(temp_file_path.data()); return false; } - record->file = kSbFileInvalid; + record->file = -1; - if ((!SbFileDelete(original_file_path.data())) || + if (unlink(original_file_path.data()) || (rename(temp_file_path.data(), original_file_path.data()) != 0)) { - SbFileClose(temp_file); - SbFileDelete(temp_file_path.data()); + close(temp_file); + unlink(temp_file_path.data()); return false; } - SbFileFlush(temp_file); + fsync(temp_file); record->file = temp_file; diff --git a/starboard/shared/pulse/pulse_audio_sink_type.cc b/starboard/shared/pulse/pulse_audio_sink_type.cc index c5eacadf1082..eb091fc508e3 100644 --- a/starboard/shared/pulse/pulse_audio_sink_type.cc +++ b/starboard/shared/pulse/pulse_audio_sink_type.cc @@ -18,13 +18,13 @@ #include #include +#include #include #include #include #include "starboard/audio_sink.h" -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/time.h" @@ -117,9 +117,9 @@ class PulseAudioSink : public SbAudioSinkPrivate { size_t last_request_size_ = 0; int64_t total_frames_played_ = 0; int64_t total_frames_written_ = 0; - atomic_double volume_{1.0}; - atomic_bool volume_updated_{true}; - atomic_bool is_paused_{false}; + std::atomic volume_{1.0}; + std::atomic_bool volume_updated_{true}; + std::atomic_bool is_paused_{false}; }; class PulseAudioSinkType : public SbAudioSinkPrivate::Type { diff --git a/starboard/shared/starboard/application.cc b/starboard/shared/starboard/application.cc index af80809ff031..1afc480ba9a9 100644 --- a/starboard/shared/starboard/application.cc +++ b/starboard/shared/starboard/application.cc @@ -42,7 +42,11 @@ void Dispatch(SbEventType type, void* data, SbEventDataDestructor destructor) { SbEvent event; event.type = type; event.data = data; +#if SB_API_VERSION >= 15 Application::Get()->sb_event_handle_callback_(&event); +#else + SbEventHandle(&event); +#endif // SB_API_VERSION >= 15 if (destructor) { destructor(event.data); } @@ -63,6 +67,7 @@ volatile SbAtomic32 g_next_event_id = 0; Application* Application::g_instance = NULL; +#if SB_API_VERSION >= 15 Application::Application(SbEventHandleCallback sb_event_handle_callback) : error_level_(0), thread_(pthread_self()), @@ -71,6 +76,13 @@ Application::Application(SbEventHandleCallback sb_event_handle_callback) sb_event_handle_callback_(sb_event_handle_callback) { SB_CHECK(sb_event_handle_callback_) << "sb_event_handle_callback_ has not been set."; +#else +Application::Application() + : error_level_(0), + thread_(pthread_self()), + start_link_(NULL), + state_(kStateUnstarted) { +#endif // SB_API_VERSION >= 15 Application* old_instance = reinterpret_cast(SbAtomicAcquire_CompareAndSwapPtr( reinterpret_cast(&g_instance), @@ -407,7 +419,11 @@ bool Application::HandleEventAndUpdateState(Application::Event* event) { OnSuspend(); } +#if SB_API_VERSION >= 15 sb_event_handle_callback_(scoped_event->event); +#else + SbEventHandle(scoped_event->event); +#endif // SB_API_VERSION >= 15 switch (scoped_event->event->type) { case kSbEventTypePreload: diff --git a/starboard/shared/starboard/application.h b/starboard/shared/starboard/application.h index 4d0c269b2b12..ab7892fa7693 100644 --- a/starboard/shared/starboard/application.h +++ b/starboard/shared/starboard/application.h @@ -46,8 +46,10 @@ class Application { public: typedef player::filter::VideoFrame VideoFrame; +#if SB_API_VERSION >= 15 // Executes a SbEventHandle method callback. SbEventHandleCallback sb_event_handle_callback_ = NULL; +#endif // SB_API_VERSION >= 15 // You can use a void(void *) function to signal that a state-transition event // has completed. @@ -155,7 +157,11 @@ class Application { int error_level; }; +#if SB_API_VERSION >= 15 explicit Application(SbEventHandleCallback sb_event_handle_callback); +#else + Application(); +#endif // SB_API_VERSION >= 15 virtual ~Application(); // Gets the current instance of the Application. DCHECKS if called before the diff --git a/starboard/shared/starboard/file_atomic_replace_write_file.cc b/starboard/shared/starboard/file_atomic_replace_write_file.cc index 5d7e48925853..3b14875e2055 100644 --- a/starboard/shared/starboard/file_atomic_replace_write_file.cc +++ b/starboard/shared/starboard/file_atomic_replace_write_file.cc @@ -14,6 +14,9 @@ #include "starboard/shared/starboard/file_atomic_replace_write_file.h" +#include +#include + #include #include "starboard/common/file.h" @@ -27,15 +30,13 @@ namespace starboard { bool SbFileAtomicReplaceWriteFile(const char* path, const char* data, int64_t data_size) { - SbFileError error; - SbFile temp_file = SbFileOpen( - path, kSbFileCreateAlways | kSbFileWrite | kSbFileRead, NULL, &error); + int temp_file = open(path, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR); - if (error != kSbFileOk) { + if (temp_file < 0) { return false; } - SbFileTruncate(temp_file, 0); + ftruncate(temp_file, 0); const char* source = data; int64_t to_write = data_size; @@ -43,12 +44,12 @@ bool SbFileAtomicReplaceWriteFile(const char* path, while (to_write > 0) { const int to_write_max = static_cast(std::min(to_write, static_cast(kSbInt32Max))); - const int bytes_written = SbFileWrite(temp_file, source, to_write_max); + const int bytes_written = write(temp_file, source, to_write_max); RecordFileWriteStat(bytes_written); if (bytes_written < 0) { - SbFileClose(temp_file); - SbFileDelete(path); + close(temp_file); + unlink(path); return false; } @@ -56,9 +57,9 @@ bool SbFileAtomicReplaceWriteFile(const char* path, to_write -= bytes_written; } - SbFileFlush(temp_file); + fsync(temp_file); - if (!SbFileClose(temp_file)) { + if (close(temp_file)) { return false; } return true; diff --git a/starboard/shared/starboard/file_mode_string_to_flags.cc b/starboard/shared/starboard/file_mode_string_to_flags.cc index b69d9741e86b..d6c217869a45 100644 --- a/starboard/shared/starboard/file_mode_string_to_flags.cc +++ b/starboard/shared/starboard/file_mode_string_to_flags.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/common/log.h" #include "starboard/common/string.h" #include "starboard/file.h" @@ -64,3 +66,5 @@ int SbFileModeStringToFlags(const char* mode) { } return flags; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/starboard/file_storage/storage_close_record.cc b/starboard/shared/starboard/file_storage/storage_close_record.cc index 70f850a6386d..0f39d69bad71 100644 --- a/starboard/shared/starboard/file_storage/storage_close_record.cc +++ b/starboard/shared/starboard/file_storage/storage_close_record.cc @@ -14,7 +14,9 @@ #include "starboard/common/storage.h" -#include "starboard/file.h" +#include + +#include "starboard/common/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" bool SbStorageCloseRecord(SbStorageRecord record) { @@ -22,8 +24,8 @@ bool SbStorageCloseRecord(SbStorageRecord record) { return false; } - if (SbFileIsValid(record->file)) { - SbFileClose(record->file); + if (starboard::IsValid(record->file)) { + close(record->file); } delete record; diff --git a/starboard/shared/starboard/file_storage/storage_delete_record.cc b/starboard/shared/starboard/file_storage/storage_delete_record.cc index 3d32365883c6..0d1bf129c858 100644 --- a/starboard/shared/starboard/file_storage/storage_delete_record.cc +++ b/starboard/shared/starboard/file_storage/storage_delete_record.cc @@ -14,10 +14,11 @@ #include "starboard/common/storage.h" +#include + #include #include "starboard/configuration_constants.h" -#include "starboard/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" #if SB_API_VERSION < 16 @@ -33,5 +34,5 @@ bool SbStorageDeleteRecord(const char* name) { return false; } - return SbFileDelete(path.data()); + return !unlink(path.data()); } diff --git a/starboard/shared/starboard/file_storage/storage_get_record_size.cc b/starboard/shared/starboard/file_storage/storage_get_record_size.cc index deda29f21bff..4e9207e1b7c1 100644 --- a/starboard/shared/starboard/file_storage/storage_get_record_size.cc +++ b/starboard/shared/starboard/file_storage/storage_get_record_size.cc @@ -14,7 +14,7 @@ #include "starboard/common/storage.h" -#include "starboard/file.h" +#include "starboard/common/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" int64_t SbStorageGetRecordSize(SbStorageRecord record) { @@ -22,15 +22,15 @@ int64_t SbStorageGetRecordSize(SbStorageRecord record) { return -1; } - if (!SbFileIsValid(record->file)) { + if (!starboard::IsValid(record->file)) { return -1; } - SbFileInfo info; - bool success = SbFileGetInfo(record->file, &info); + struct stat info; + bool success = !fstat(record->file, &info); if (!success) { return -1; } - return info.size; + return info.st_size; } diff --git a/starboard/shared/starboard/file_storage/storage_internal.h b/starboard/shared/starboard/file_storage/storage_internal.h index c59edf50d377..268a2d1f462e 100644 --- a/starboard/shared/starboard/file_storage/storage_internal.h +++ b/starboard/shared/starboard/file_storage/storage_internal.h @@ -21,13 +21,12 @@ #include "starboard/common/storage.h" #include "starboard/common/string.h" -#include "starboard/file.h" #include "starboard/shared/internal_only.h" #include "starboard/shared/starboard/get_home_directory.h" struct SbStorageRecordPrivate { void* unused_user; // deprecated in SB 16 - SbFile file; + int file; std::string name; }; diff --git a/starboard/shared/starboard/file_storage/storage_open_record.cc b/starboard/shared/starboard/file_storage/storage_open_record.cc index 5eee17162270..eaa32c79790e 100644 --- a/starboard/shared/starboard/file_storage/storage_open_record.cc +++ b/starboard/shared/starboard/file_storage/storage_open_record.cc @@ -14,11 +14,13 @@ #include "starboard/common/storage.h" +#include + #include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/configuration_constants.h" -#include "starboard/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" #if SB_API_VERSION < 16 @@ -36,9 +38,8 @@ SbStorageRecord SbStorageOpenRecord(const char* name) { // This will always create the storage file, even if it is just opened and // closed without doing any operation. - SbFile file = SbFileOpen( - path.data(), kSbFileOpenAlways | kSbFileRead | kSbFileWrite, NULL, NULL); - if (!SbFileIsValid(file)) { + int file = open(path.data(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); + if (!starboard::IsValid(file)) { return kSbStorageInvalidRecord; } diff --git a/starboard/shared/starboard/file_storage/storage_read_record.cc b/starboard/shared/starboard/file_storage/storage_read_record.cc index ff316e1abdd2..7dc3745dc960 100644 --- a/starboard/shared/starboard/file_storage/storage_read_record.cc +++ b/starboard/shared/starboard/file_storage/storage_read_record.cc @@ -14,8 +14,11 @@ #include "starboard/common/storage.h" +#include + #include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/common/string.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" @@ -27,16 +30,16 @@ int64_t SbStorageReadRecord(SbStorageRecord record, return -1; } - if (!SbFileIsValid(record->file)) { + if (!starboard::IsValid(record->file)) { return -1; } - int64_t total = SbFileSeek(record->file, kSbFileFromEnd, 0); + int64_t total = lseek(record->file, 0, SEEK_END); if (total > data_size) { total = data_size; } - int64_t position = SbFileSeek(record->file, kSbFileFromBegin, 0); + int64_t position = lseek(record->file, 0, SEEK_SET); if (position != 0) { return -1; } @@ -46,7 +49,7 @@ int64_t SbStorageReadRecord(SbStorageRecord record, while (to_read > 0) { int to_read_max = static_cast(std::min(to_read, static_cast(kSbInt32Max))); - int bytes_read = SbFileRead(record->file, destination, to_read_max); + int bytes_read = read(record->file, destination, to_read_max); if (bytes_read < 0) { return -1; } diff --git a/starboard/shared/starboard/link_receiver.cc b/starboard/shared/starboard/link_receiver.cc index dcc9a3f41cea..c082fb2e5cc8 100644 --- a/starboard/shared/starboard/link_receiver.cc +++ b/starboard/shared/starboard/link_receiver.cc @@ -14,12 +14,12 @@ #include "starboard/shared/starboard/link_receiver.h" +#include #include #include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/common/semaphore.h" @@ -218,7 +218,7 @@ class LinkReceiver::Impl { pthread_t thread_; // An atomic flag that indicates whether to quit to the server thread. - atomic_bool quit_; + std::atomic_bool quit_{false}; // The waiter to register sockets with and block on. SbSocketWaiter waiter_; diff --git a/starboard/shared/starboard/media/media_get_audio_configuration.cc b/starboard/shared/starboard/media/media_get_audio_configuration.cc index 542ac80fff78..038a766decf3 100644 --- a/starboard/shared/starboard/media/media_get_audio_configuration.cc +++ b/starboard/shared/starboard/media/media_get_audio_configuration.cc @@ -31,7 +31,12 @@ bool SbMediaGetAudioConfiguration( *out_configuration = {}; +#if SB_API_VERSION >= 15 out_configuration->connector = kSbMediaAudioConnectorUnknown; +#else // SB_API_VERSION >= 15 + out_configuration->index = 0; + out_configuration->connector = kSbMediaAudioConnectorNone; +#endif // SB_API_VERSION >= 15 out_configuration->latency = 0; out_configuration->coding_type = kSbMediaAudioCodingTypePcm; out_configuration->number_of_channels = SbAudioSinkGetMaxChannels(); diff --git a/starboard/shared/starboard/media/media_util.cc b/starboard/shared/starboard/media/media_util.cc index e772b4fafff4..e0541d47dc08 100644 --- a/starboard/shared/starboard/media/media_util.cc +++ b/starboard/shared/starboard/media/media_util.cc @@ -169,9 +169,13 @@ bool operator!=(const AudioStreamInfo& left, const AudioStreamInfo& right) { AudioSampleInfo& AudioSampleInfo::operator=( const SbMediaAudioSampleInfo& that) { +#if SB_API_VERSION >= 15 stream_info = that.stream_info; discarded_duration_from_front = that.discarded_duration_from_front; discarded_duration_from_back = that.discarded_duration_from_back; +#else // SB_API_VERSION >= 15 + stream_info = that; +#endif // SB_API_VERSION >= 15 return *this; } @@ -189,11 +193,15 @@ void AudioSampleInfo::ConvertTo( SB_DCHECK(audio_sample_info); *audio_sample_info = {}; +#if SB_API_VERSION >= 15 stream_info.ConvertTo(&audio_sample_info->stream_info); audio_sample_info->discarded_duration_from_front = discarded_duration_from_front; audio_sample_info->discarded_duration_from_back = discarded_duration_from_back; +#else // SB_API_VERSION >= 15 + stream_info.ConvertTo(audio_sample_info); +#endif // SB_API_VERSION >= 15 } void AudioSampleInfo::ConvertTo( @@ -249,7 +257,11 @@ bool operator!=(const VideoStreamInfo& left, const VideoStreamInfo& right) { VideoSampleInfo& VideoSampleInfo::operator=( const SbMediaVideoSampleInfo& that) { +#if SB_API_VERSION >= 15 stream_info = that.stream_info; +#else // SB_API_VERSION >= 15 + stream_info = that; +#endif // SB_API_VERSION >= 15 is_key_frame = that.is_key_frame; return *this; } @@ -266,7 +278,11 @@ void VideoSampleInfo::ConvertTo( SB_DCHECK(video_sample_info); *video_sample_info = {}; +#if SB_API_VERSION >= 15 stream_info.ConvertTo(&video_sample_info->stream_info); +#else // SB_API_VERSION >= 15 + stream_info.ConvertTo(video_sample_info); +#endif // SB_API_VERSION >= 15 video_sample_info->is_key_frame = is_key_frame; } @@ -462,8 +478,13 @@ bool operator==(const SbMediaColorMetadata& metadata_1, bool operator==(const SbMediaVideoSampleInfo& sample_info_1, const SbMediaVideoSampleInfo& sample_info_2) { +#if SB_API_VERSION >= 15 const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1.stream_info; const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2.stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1; + const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2; +#endif // SB_API_VERSION >= 15 if (stream_info_1.codec != stream_info_2.codec) { return false; @@ -492,6 +513,8 @@ bool operator==(const SbMediaVideoSampleInfo& sample_info_1, return stream_info_1.color_metadata == stream_info_2.color_metadata; } +#if SB_API_VERSION >= 15 + bool operator==(const SbMediaVideoStreamInfo& stream_info_1, const SbMediaVideoStreamInfo& stream_info_2) { if (stream_info_1.codec != stream_info_2.codec) { @@ -517,6 +540,8 @@ bool operator==(const SbMediaVideoStreamInfo& stream_info_1, return stream_info_1.color_metadata == stream_info_2.color_metadata; } +#endif // SB_API_VERSION >= 15 + bool operator!=(const SbMediaColorMetadata& metadata_1, const SbMediaColorMetadata& metadata_2) { return !(metadata_1 == metadata_2); @@ -527,7 +552,9 @@ bool operator!=(const SbMediaVideoSampleInfo& sample_info_1, return !(sample_info_1 == sample_info_2); } +#if SB_API_VERSION >= 15 bool operator!=(const SbMediaVideoStreamInfo& stream_info_1, const SbMediaVideoStreamInfo& stream_info_2) { return !(stream_info_1 == stream_info_2); } +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/starboard/media/media_util.h b/starboard/shared/starboard/media/media_util.h index 99f24c4cbe98..030a53fd084c 100644 --- a/starboard/shared/starboard/media/media_util.h +++ b/starboard/shared/starboard/media/media_util.h @@ -178,15 +178,19 @@ bool operator==(const SbMediaColorMetadata& metadata_1, bool operator==(const SbMediaVideoSampleInfo& sample_info_1, const SbMediaVideoSampleInfo& sample_info_2); +#if SB_API_VERSION >= 15 bool operator==(const SbMediaVideoStreamInfo& stream_info_1, const SbMediaVideoStreamInfo& stream_info_2); +#endif // SB_API_VERSION >= 15 bool operator!=(const SbMediaColorMetadata& metadata_1, const SbMediaColorMetadata& metadata_2); bool operator!=(const SbMediaVideoSampleInfo& sample_info_1, const SbMediaVideoSampleInfo& sample_info_2); +#if SB_API_VERSION >= 15 bool operator!=(const SbMediaVideoStreamInfo& stream_info_1, const SbMediaVideoStreamInfo& stream_info_2); +#endif // SB_API_VERSION >= 15 #endif // STARBOARD_SHARED_STARBOARD_MEDIA_MEDIA_UTIL_H_ diff --git a/starboard/shared/starboard/media/media_util_test.cc b/starboard/shared/starboard/media/media_util_test.cc index c49698f49ae6..a76f5c4059e1 100644 --- a/starboard/shared/starboard/media/media_util_test.cc +++ b/starboard/shared/starboard/media/media_util_test.cc @@ -175,7 +175,11 @@ TEST(AudioSampleInfoTest, DefaultCtor) { TEST(AudioSampleInfoTest, SbMediaAudioSampleInfo) { SbMediaAudioSampleInfo original = {}; +#if SB_API_VERSION >= 15 SbMediaAudioStreamInfo& stream_info = original.stream_info; +#else // SB_API_VERSION >= 15 + SbMediaAudioStreamInfo& stream_info = original; +#endif // SB_API_VERSION >= 15 stream_info.codec = kSbMediaAudioCodecOpus; stream_info.mime = "audio/webm"; @@ -240,7 +244,11 @@ TEST(VideoSampleInfoTest, DefaultCtor) { TEST(VideoSampleInfoTest, SbMediaVideoSampleInfo) { SbMediaVideoSampleInfo original = {}; +#if SB_API_VERSION >= 15 SbMediaVideoStreamInfo& stream_info = original.stream_info; +#else // SB_API_VERSION >= 15 + SbMediaVideoStreamInfo& stream_info = original; +#endif // SB_API_VERSION >= 15 original.is_key_frame = true; stream_info.codec = kSbMediaVideoCodecAv1; diff --git a/starboard/shared/starboard/media/mime_util.cc b/starboard/shared/starboard/media/mime_util.cc index e0fc0280558d..23f83dd7bcff 100644 --- a/starboard/shared/starboard/media/mime_util.cc +++ b/starboard/shared/starboard/media/mime_util.cc @@ -111,11 +111,13 @@ bool IsSupportedAudioCodec(const ParsedMimeInfo& mime_info) { return false; } break; +#if SB_API_VERSION >= 15 case kSbMediaAudioCodecIamf: if (mime_type.subtype() != "mp4") { return false; } break; +#endif // SB_API_VERSION >= 15 } if (!IsAudioOutputSupported(kSbMediaAudioCodingTypePcm, diff --git a/starboard/shared/starboard/net_log.cc b/starboard/shared/starboard/net_log.cc index 632fdc847221..6b0aee3943a6 100644 --- a/starboard/shared/starboard/net_log.cc +++ b/starboard/shared/starboard/net_log.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -26,7 +27,6 @@ #include #include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/once.h" @@ -197,7 +197,7 @@ class BufferedSocketWriter { SbSocketError err = SbSocketGetLastError(dest_socket); SbSocketClearLastError(dest_socket); if (err == kSbSocketPending) { - blocked_counts_.increment(); + ++blocked_counts_; WaitUntilWritableOrConnectionReset(dest_socket); continue; } else if (IsConnectionReset(err)) { @@ -251,7 +251,7 @@ class BufferedSocketWriter { int chunk_size_; Mutex log_mutex_; std::deque log_; - atomic_int32_t blocked_counts_; + std::atomic blocked_counts_{0}; }; // This class will listen to the provided socket for a client @@ -383,7 +383,7 @@ class NetLogServer { std::unique_ptr socket_listener_; std::unique_ptr writer_thread_; Semaphore writer_thread_sema_; - atomic_bool is_joined_; + std::atomic_bool is_joined_{false}; BufferedSocketWriter buffered_socket_writer_; }; diff --git a/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.cc b/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.cc index 67614ac7a271..011063eab0a7 100644 --- a/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.cc +++ b/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.cc @@ -370,7 +370,7 @@ void AudioRendererPcm::GetSourceStatus(int* frames_in_buffer, bool* is_playing, bool* is_eos_reached) { #if SB_PLAYER_FILTER_ENABLE_STATE_CHECK - sink_callbacks_since_last_check_.increment(); + ++sink_callbacks_since_last_check_; #endif // SB_PLAYER_FILTER_ENABLE_STATE_CHECK { @@ -425,7 +425,7 @@ void AudioRendererPcm::GetSourceStatus(int* frames_in_buffer, void AudioRendererPcm::ConsumeFrames(int frames_consumed, int64_t frames_consumed_at) { #if SB_PLAYER_FILTER_ENABLE_STATE_CHECK - sink_callbacks_since_last_check_.increment(); + ++sink_callbacks_since_last_check_; #endif // SB_PLAYER_FILTER_ENABLE_STATE_CHECK // Note that occasionally thread context switch may cause that the time diff --git a/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.h b/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.h index 6a424b4c20f7..a5eec80bb46f 100644 --- a/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.h +++ b/starboard/shared/starboard/player/filter/audio_renderer_internal_pcm.h @@ -15,12 +15,12 @@ #ifndef STARBOARD_SHARED_STARBOARD_PLAYER_FILTER_AUDIO_RENDERER_INTERNAL_PCM_H_ #define STARBOARD_SHARED_STARBOARD_PLAYER_FILTER_AUDIO_RENDERER_INTERNAL_PCM_H_ +#include #include #include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/optional.h" @@ -206,7 +206,7 @@ class AudioRendererPcm : public AudioRenderer, static const int64_t kCheckAudioSinkStatusInterval = 1'000'000; // 1 second void CheckAudioSinkStatus(); - atomic_int32_t sink_callbacks_since_last_check_; + std::atomic sink_callbacks_since_last_check_{0}; #endif // SB_PLAYER_FILTER_ENABLE_STATE_CHECK }; diff --git a/starboard/shared/starboard/player/filter/filter_based_player_worker_handler.cc b/starboard/shared/starboard/player/filter/filter_based_player_worker_handler.cc index c905deb85720..f55a639d2448 100644 --- a/starboard/shared/starboard/player/filter/filter_based_player_worker_handler.cc +++ b/starboard/shared/starboard/player/filter/filter_based_player_worker_handler.cc @@ -77,11 +77,19 @@ FilterBasedPlayerWorkerHandler::FilterBasedPlayerWorkerHandler( SbDecodeTargetGraphicsContextProvider* provider) : JobOwner(kDetached), drm_system_(creation_param->drm_system), +#if SB_API_VERSION >= 15 audio_stream_info_(creation_param->audio_stream_info), +#else // SB_API_VERSION >= 15 + audio_stream_info_(creation_param->audio_sample_info), +#endif // SB_API_VERSION >= 15 output_mode_(creation_param->output_mode), max_video_input_size_(0), decode_target_graphics_context_provider_(provider), +#if SB_API_VERSION >= 15 video_stream_info_(creation_param->video_stream_info) { +#else // SB_API_VERSION >= 15 + video_stream_info_(creation_param->video_sample_info) { +#endif // SB_API_VERSION >= 15 update_job_ = std::bind(&FilterBasedPlayerWorkerHandler::Update, this); } diff --git a/starboard/shared/starboard/player/filter/punchout_video_renderer_sink.h b/starboard/shared/starboard/player/filter/punchout_video_renderer_sink.h index dc4d3ed47775..bbfae144f33f 100644 --- a/starboard/shared/starboard/player/filter/punchout_video_renderer_sink.h +++ b/starboard/shared/starboard/player/filter/punchout_video_renderer_sink.h @@ -16,8 +16,8 @@ #define STARBOARD_SHARED_STARBOARD_PLAYER_FILTER_PUNCHOUT_VIDEO_RENDERER_SINK_H_ #include +#include -#include "starboard/common/atomic.h" #include "starboard/common/mutex.h" #include "starboard/media.h" #include "starboard/player.h" @@ -50,7 +50,7 @@ class PunchoutVideoRendererSink : public VideoRendererSink { int64_t render_interval_; // microseconds RenderCB render_cb_; pthread_t thread_; - atomic_bool stop_requested_; + std::atomic_bool stop_requested_{false}; Mutex mutex_; int z_index_; diff --git a/starboard/shared/starboard/player/filter/stub_audio_decoder.cc b/starboard/shared/starboard/player/filter/stub_audio_decoder.cc index b2d0d3929001..15c93ec428b8 100644 --- a/starboard/shared/starboard/player/filter/stub_audio_decoder.cc +++ b/starboard/shared/starboard/player/filter/stub_audio_decoder.cc @@ -245,10 +245,12 @@ void StubAudioDecoder::DecodeEndOfStream() { } else if (codec_ == kSbMediaAudioCodecAc3 || codec_ == kSbMediaAudioCodecEac3) { frames_per_input_ = 1536; +#if SB_API_VERSION >= 15 } else if (codec_ == kSbMediaAudioCodecIamf) { // The max iamf frames per input varies depending on the stream. // Assume 2048 max. frames_per_input_ = 2048; +#endif // SB_API_VERSION >= 15 } else { SB_NOTREACHED() << "Unsupported audio codec " << codec_; } diff --git a/starboard/shared/starboard/player/filter/testing/test_util.cc b/starboard/shared/starboard/player/filter/testing/test_util.cc index ddab7db227ad..3cc4bf5078e7 100644 --- a/starboard/shared/starboard/player/filter/testing/test_util.cc +++ b/starboard/shared/starboard/player/filter/testing/test_util.cc @@ -66,9 +66,11 @@ std::string GetContentTypeFromAudioCodec(SbMediaAudioCodec audio_codec, case kSbMediaAudioCodecEac3: content_type = "audio/mp4; codecs=\"ec-3\""; break; +#if SB_API_VERSION >= 15 case kSbMediaAudioCodecIamf: content_type = "audio/mp4; codecs=\"iamf\""; break; +#endif // SB_API_VERSION >= 15 default: SB_NOTREACHED(); } @@ -109,8 +111,10 @@ std::vector GetSupportedAudioTestFiles( "beneath_the_canopy_opus_stereo.dmp", "beneath_the_canopy_opus_mono.dmp", "heaac.dmp", +#if SB_API_VERSION >= 15 "iamf_base_profile_stereo_ambisonics.dmp", "iamf_simple_profile_5_1.dmp", +#endif // SB_API_VERSION >= 15 "sintel_329_ec3.dmp", "sintel_381_ac3.dmp"}; @@ -283,7 +287,11 @@ media::VideoStreamInfo CreateVideoStreamInfo(SbMediaVideoCodec codec) { } bool IsPartialAudioSupported() { +#if SB_API_VERSION >= 15 return true; +#else // SB_API_VERSION >= 15 + return SbSystemGetExtension(kCobaltExtensionEnhancedAudioName) != nullptr; +#endif // SB_API_VERSION >= 15 } scoped_refptr GetAudioInputBuffer( @@ -305,12 +313,34 @@ scoped_refptr GetAudioInputBuffer( SB_DCHECK(dmp_reader); auto player_sample_info = dmp_reader->GetPlayerSampleInfo(kSbMediaTypeAudio, index); +#if SB_API_VERSION >= 15 player_sample_info.audio_sample_info.discarded_duration_from_front = discarded_duration_from_front; player_sample_info.audio_sample_info.discarded_duration_from_back = discarded_duration_from_back; auto input_buffer = new InputBuffer(StubDeallocateSampleFunc, nullptr, nullptr, player_sample_info); +#else // SB_API_VERSION >= 15 + media::AudioSampleInfo audio_sample_info( + player_sample_info.audio_sample_info); + audio_sample_info.discarded_duration_from_front = + discarded_duration_from_front; + audio_sample_info.discarded_duration_from_back = discarded_duration_from_back; + + CobaltExtensionEnhancedAudioPlayerSampleInfo enhanced_audio_sample_info; + enhanced_audio_sample_info.type = player_sample_info.type; + enhanced_audio_sample_info.buffer = player_sample_info.buffer; + enhanced_audio_sample_info.buffer_size = player_sample_info.buffer_size; + enhanced_audio_sample_info.timestamp = player_sample_info.timestamp; + enhanced_audio_sample_info.side_data = player_sample_info.side_data; + enhanced_audio_sample_info.side_data_count = + player_sample_info.side_data_count; + audio_sample_info.ConvertTo(&enhanced_audio_sample_info.audio_sample_info); + enhanced_audio_sample_info.drm_info = player_sample_info.drm_info; + + auto input_buffer = new InputBuffer(StubDeallocateSampleFunc, nullptr, + nullptr, enhanced_audio_sample_info); +#endif // SB_API_VERSION >= 15 return input_buffer; } diff --git a/starboard/shared/starboard/player/filter/video_renderer_internal_impl.cc b/starboard/shared/starboard/player/filter/video_renderer_internal_impl.cc index 2b7c6410ac6b..f7c50204dc91 100644 --- a/starboard/shared/starboard/player/filter/video_renderer_internal_impl.cc +++ b/starboard/shared/starboard/player/filter/video_renderer_internal_impl.cc @@ -44,12 +44,7 @@ VideoRendererImpl::VideoRendererImpl( : media_time_provider_(media_time_provider), algorithm_(std::move(algorithm)), sink_(sink), - decoder_(std::move(decoder)), - end_of_stream_written_(false), - ended_cb_called_(false), - need_more_input_(true), - seeking_(false), - number_of_frames_(0) { + decoder_(std::move(decoder)) { SB_DCHECK(decoder_ != NULL); SB_DCHECK(algorithm_ != NULL); SB_DCHECK(decoder_->GetMaxNumberOfCachedFrames() > 1); @@ -284,7 +279,7 @@ void VideoRendererImpl::OnDecoderStatus( if (decoder_frames_.empty() || frame->is_end_of_stream() || frame->timestamp() > decoder_frames_.back()->timestamp()) { decoder_frames_.push_back(frame); - number_of_frames_.increment(); + ++number_of_frames_; } } diff --git a/starboard/shared/starboard/player/filter/video_renderer_internal_impl.h b/starboard/shared/starboard/player/filter/video_renderer_internal_impl.h index 36b310e64abe..45edbb4b61ad 100644 --- a/starboard/shared/starboard/player/filter/video_renderer_internal_impl.h +++ b/starboard/shared/starboard/player/filter/video_renderer_internal_impl.h @@ -15,10 +15,10 @@ #ifndef STARBOARD_SHARED_STARBOARD_PLAYER_FILTER_VIDEO_RENDERER_INTERNAL_IMPL_H_ #define STARBOARD_SHARED_STARBOARD_PLAYER_FILTER_VIDEO_RENDERER_INTERNAL_IMPL_H_ +#include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/ref_counted.h" @@ -97,16 +97,16 @@ class VideoRendererImpl : public VideoRenderer, private JobQueue::JobOwner { // performance by keeping track of whether we already have a fresh decoder, // and can thus avoid doing a full reset. bool first_input_written_ = false; - atomic_bool end_of_stream_written_; - atomic_bool end_of_stream_decoded_; - atomic_bool ended_cb_called_; + std::atomic_bool end_of_stream_written_{false}; + std::atomic_bool end_of_stream_decoded_{false}; + std::atomic_bool ended_cb_called_{false}; - atomic_bool need_more_input_; - atomic_bool seeking_; + std::atomic_bool need_more_input_{true}; + std::atomic_bool seeking_{false}; int64_t seeking_to_time_ = 0; // microseconds // |number_of_frames_| = decoder_frames_.size() + sink_frames_.size() - atomic_int32_t number_of_frames_; + std::atomic number_of_frames_{0}; // |sink_frames_| is locked inside VideoRenderer::Render() when calling // algorithm_->Render(). So OnDecoderStatus() won't try to lock and append // the decoded frames to |sink_frames_| directly to avoid being blocked. It diff --git a/starboard/shared/starboard/player/player_create.cc b/starboard/shared/starboard/player/player_create.cc index 7a990afc5aa4..291854b22581 100644 --- a/starboard/shared/starboard/player/player_create.cc +++ b/starboard/shared/starboard/player/player_create.cc @@ -61,10 +61,17 @@ SbPlayer SbPlayerCreate(SbWindow window, return kSbPlayerInvalid; } +#if SB_API_VERSION >= 15 const SbMediaAudioStreamInfo& audio_stream_info = creation_param->audio_stream_info; const SbMediaVideoStreamInfo& video_stream_info = creation_param->video_stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaAudioSampleInfo& audio_stream_info = + creation_param->audio_sample_info; + const SbMediaVideoSampleInfo& video_stream_info = + creation_param->video_sample_info; +#endif // SB_API_VERSION >= 15 bool has_audio = audio_stream_info.codec != kSbMediaAudioCodecNone; bool has_video = video_stream_info.codec != kSbMediaVideoCodecNone; diff --git a/starboard/shared/starboard/player/player_get_audio_configuration.cc b/starboard/shared/starboard/player/player_get_audio_configuration.cc index 90ccc81d65e2..36a3e110bd84 100644 --- a/starboard/shared/starboard/player/player_get_audio_configuration.cc +++ b/starboard/shared/starboard/player/player_get_audio_configuration.cc @@ -18,6 +18,8 @@ #include "starboard/media.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 + bool SbPlayerGetAudioConfiguration( SbPlayer player, int index, @@ -28,3 +30,5 @@ bool SbPlayerGetAudioConfiguration( return player->GetAudioConfiguration(index, out_audio_configuration); } + +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/starboard/player/player_get_info.cc b/starboard/shared/starboard/player/player_get_info.cc index c16baa73ccca..7c1659d97161 100644 --- a/starboard/shared/starboard/player/player_get_info.cc +++ b/starboard/shared/starboard/player/player_get_info.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info) { +#else // SB_API_VERSION >= 15 +void SbPlayerGetInfo2(SbPlayer player, SbPlayerInfo2* out_player_info) { +#endif // SB_API_VERSION >= 15 if (!SbPlayerIsValid(player)) { SB_DLOG(WARNING) << "player is invalid."; return; diff --git a/starboard/shared/starboard/player/player_get_preferred_output_mode_prefer_punchout.cc b/starboard/shared/starboard/player/player_get_preferred_output_mode_prefer_punchout.cc index f4863a262e31..a766f13604ad 100644 --- a/starboard/shared/starboard/player/player_get_preferred_output_mode_prefer_punchout.cc +++ b/starboard/shared/starboard/player/player_get_preferred_output_mode_prefer_punchout.cc @@ -28,10 +28,17 @@ SbPlayerOutputMode SbPlayerGetPreferredOutputMode( return kSbPlayerOutputModeInvalid; } +#if SB_API_VERSION >= 15 const SbMediaAudioStreamInfo& audio_stream_info = creation_param->audio_stream_info; const SbMediaVideoStreamInfo& video_stream_info = creation_param->video_stream_info; +#else // SB_API_VERSION >= 15 + const SbMediaAudioSampleInfo& audio_stream_info = + creation_param->audio_sample_info; + const SbMediaVideoSampleInfo& video_stream_info = + creation_param->video_sample_info; +#endif // SB_API_VERSION >= 15 if (audio_stream_info.codec != kSbMediaAudioCodecNone && !audio_stream_info.mime) { diff --git a/starboard/shared/starboard/player/player_internal.cc b/starboard/shared/starboard/player/player_internal.cc index be054943a366..225d4a8d96ae 100644 --- a/starboard/shared/starboard/player/player_internal.cc +++ b/starboard/shared/starboard/player/player_internal.cc @@ -116,7 +116,11 @@ void SbPlayerPrivate::SetBounds(int z_index, // TODO: Wait until a frame is rendered with the updated bounds. } +#if SB_API_VERSION >= 15 void SbPlayerPrivate::GetInfo(SbPlayerInfo* out_player_info) { +#else // SB_API_VERSION >= 15 +void SbPlayerPrivate::GetInfo(SbPlayerInfo2* out_player_info) { +#endif // SB_API_VERSION >= 15 SB_DCHECK(out_player_info != NULL); starboard::ScopedLock lock(mutex_); diff --git a/starboard/shared/starboard/player/player_internal.h b/starboard/shared/starboard/player/player_internal.h index 1aa6026fd583..05d64a11886a 100644 --- a/starboard/shared/starboard/player/player_internal.h +++ b/starboard/shared/starboard/player/player_internal.h @@ -54,7 +54,11 @@ struct SbPlayerPrivate { void WriteEndOfStream(SbMediaType stream_type); void SetBounds(int z_index, int x, int y, int width, int height); +#if SB_API_VERSION >= 15 void GetInfo(SbPlayerInfo* out_player_info); +#else // SB_API_VERSION >= 15 + void GetInfo(SbPlayerInfo2* out_player_info); +#endif // SB_API_VERSION >= 15 void SetPause(bool pause); void SetPlaybackRate(double playback_rate); void SetVolume(double volume); diff --git a/starboard/shared/starboard/player/player_seek.cc b/starboard/shared/starboard/player/player_seek.cc index 694fcd80476d..9b1281488bbc 100644 --- a/starboard/shared/starboard/player/player_seek.cc +++ b/starboard/shared/starboard/player/player_seek.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket) { +#else // SB_API_VERSION >= 15 +void SbPlayerSeek2(SbPlayer player, int64_t seek_to_timestamp, int ticket) { +#endif // SB_API_VERSION >= 15 if (!SbPlayerIsValid(player)) { SB_DLOG(WARNING) << "player is invalid."; return; diff --git a/starboard/shared/starboard/player/player_write_samples.cc b/starboard/shared/starboard/player/player_write_samples.cc index 73dfeb2fd0f5..37c66692e443 100644 --- a/starboard/shared/starboard/player/player_write_samples.cc +++ b/starboard/shared/starboard/player/player_write_samples.cc @@ -17,7 +17,11 @@ #include "starboard/common/log.h" #include "starboard/shared/starboard/player/player_internal.h" +#if SB_API_VERSION >= 15 void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, int number_of_sample_infos) { diff --git a/starboard/shared/starboard/player/video_dmp_reader.cc b/starboard/shared/starboard/player/video_dmp_reader.cc index d65b1f68bafd..bfdf43515361 100644 --- a/starboard/shared/starboard/player/video_dmp_reader.cc +++ b/starboard/shared/starboard/player/video_dmp_reader.cc @@ -162,9 +162,11 @@ std::string VideoDmpReader::audio_mime_type() const { case kSbMediaAudioCodecPcm: ss << "audio/wav; codecs=\"1\";"; break; +#if SB_API_VERSION >= 15 case kSbMediaAudioCodecIamf: ss << "audio/mp4; codecs=\"iamf\";"; break; +#endif // SB_API_VERSION >= 15 default: SB_NOTREACHED() << "Unsupported audio codec: " << dmp_info_.audio_codec; } diff --git a/starboard/shared/starboard/player/video_dmp_writer.cc b/starboard/shared/starboard/player/video_dmp_writer.cc index 9d6b2bdc45fb..de5ce1bc461d 100644 --- a/starboard/shared/starboard/player/video_dmp_writer.cc +++ b/starboard/shared/starboard/player/video_dmp_writer.cc @@ -14,6 +14,9 @@ #include "starboard/shared/starboard/player/video_dmp_writer.h" +#include +#include + #include #include #include @@ -71,17 +74,16 @@ SB_ONCE_INITIALIZE_FUNCTION(PlayerToWriterMap, GetOrCreatePlayerToWriterMap); } // namespace -VideoDmpWriter::VideoDmpWriter() : file_(kSbFileInvalid) { +VideoDmpWriter::VideoDmpWriter() : file_(-1) { int index = 0; std::string file_name; - while (!SbFileIsValid(file_)) { + while (!IsValid(file_)) { std::stringstream ss; ss << "video_" << index << ".dmp"; file_name = ss.str(); - bool created = false; - file_ = SbFileOpen(file_name.c_str(), kSbFileCreateOnly | kSbFileWrite, - &created, NULL); + file_ = + open(file_name.c_str(), O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR); ++index; } SB_LOG(INFO) << "Dump video content to " << file_name; @@ -93,7 +95,7 @@ VideoDmpWriter::VideoDmpWriter() : file_(kSbFileInvalid) { } VideoDmpWriter::~VideoDmpWriter() { - SbFileClose(file_); + close(file_); } // static @@ -188,7 +190,7 @@ void VideoDmpWriter::DumpAccessUnit( } int VideoDmpWriter::WriteToFile(const void* buffer, int size) { - int result = SbFileWrite(file_, static_cast(buffer), size); + int result = write(file_, static_cast(buffer), size); RecordFileWriteStat(result); return result; } diff --git a/starboard/shared/starboard/player/video_dmp_writer.h b/starboard/shared/starboard/player/video_dmp_writer.h index 11484d527a4e..4869f160ac5a 100644 --- a/starboard/shared/starboard/player/video_dmp_writer.h +++ b/starboard/shared/starboard/player/video_dmp_writer.h @@ -52,7 +52,7 @@ class VideoDmpWriter { void DumpAccessUnit(const scoped_refptr& input_buffer); int WriteToFile(const void* buffer, int size); - SbFile file_; + int file_; WriteCB write_cb_; }; diff --git a/starboard/shared/starboard/queue_application.cc b/starboard/shared/starboard/queue_application.cc index bb4a186821ab..ca7dd6524a0a 100644 --- a/starboard/shared/starboard/queue_application.cc +++ b/starboard/shared/starboard/queue_application.cc @@ -14,7 +14,8 @@ #include "starboard/shared/starboard/queue_application.h" -#include "starboard/common/atomic.h" +#include + #include "starboard/common/condition_variable.h" #include "starboard/common/log.h" #include "starboard/common/time.h" @@ -92,11 +93,11 @@ void QueueApplication::CancelTimedEvent(SbEventId event_id) { void QueueApplication::InjectAndProcess(SbEventType type, bool checkSystemEvents) { - atomic_bool event_processed; + std::atomic_bool event_processed{false}; Event* flagged_event = new Event( - type, const_cast(&event_processed), [](void* flag) { + type, const_cast(&event_processed), [](void* flag) { auto* bool_flag = - const_cast(static_cast(flag)); + const_cast(static_cast(flag)); bool_flag->store(true); }); Inject(flagged_event); diff --git a/starboard/shared/starboard/queue_application.h b/starboard/shared/starboard/queue_application.h index c8c90ecccd4a..8f039d9b7adb 100644 --- a/starboard/shared/starboard/queue_application.h +++ b/starboard/shared/starboard/queue_application.h @@ -35,8 +35,12 @@ namespace starboard { // manage event dispatching. class QueueApplication : public Application { public: +#if SB_API_VERSION >= 15 explicit QueueApplication(SbEventHandleCallback sb_event_handle_callback) : Application(sb_event_handle_callback) {} +#else + QueueApplication() {} +#endif // SB_API_VERSION >= 15 ~QueueApplication() override {} protected: diff --git a/starboard/shared/stub/file_can_open.cc b/starboard/shared/stub/file_can_open.cc index 7335af26ad2f..132438067b99 100644 --- a/starboard/shared/stub/file_can_open.cc +++ b/starboard/shared/stub/file_can_open.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileCanOpen(const char* path, int flags) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_close.cc b/starboard/shared/stub/file_close.cc index 47df9f2080d0..768d28e26435 100644 --- a/starboard/shared/stub/file_close.cc +++ b/starboard/shared/stub/file_close.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileClose(SbFile file) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_delete.cc b/starboard/shared/stub/file_delete.cc index ff3225fdd7e5..298b5e0912bf 100644 --- a/starboard/shared/stub/file_delete.cc +++ b/starboard/shared/stub/file_delete.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileDelete(const char* path) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_exists.cc b/starboard/shared/stub/file_exists.cc index f446ca18ceee..37ccdd18ab7c 100644 --- a/starboard/shared/stub/file_exists.cc +++ b/starboard/shared/stub/file_exists.cc @@ -19,4 +19,5 @@ bool SbFileExists(const char* path) { return false; } -#endif + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/stub/file_flush.cc b/starboard/shared/stub/file_flush.cc index 5598957a4628..48268327c115 100644 --- a/starboard/shared/stub/file_flush.cc +++ b/starboard/shared/stub/file_flush.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileFlush(SbFile file) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_get_info.cc b/starboard/shared/stub/file_get_info.cc index 40cf2ee956ee..aa8d32f762f2 100644 --- a/starboard/shared/stub/file_get_info.cc +++ b/starboard/shared/stub/file_get_info.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileGetInfo(SbFile file, SbFileInfo* out_info) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_open.cc b/starboard/shared/stub/file_open.cc index fe3332bdcca0..084fbd7eb37b 100644 --- a/starboard/shared/stub/file_open.cc +++ b/starboard/shared/stub/file_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" SbFile SbFileOpen(const char* path, @@ -20,3 +22,5 @@ SbFile SbFileOpen(const char* path, SbFileError* out_error) { return kSbFileInvalid; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_read.cc b/starboard/shared/stub/file_read.cc index 4bf60654861f..8db62d342148 100644 --- a/starboard/shared/stub/file_read.cc +++ b/starboard/shared/stub/file_read.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" int SbFileRead(SbFile file, char* data, int size) { return 0; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_seek.cc b/starboard/shared/stub/file_seek.cc index ac2dc2402013..3655631fd497 100644 --- a/starboard/shared/stub/file_seek.cc +++ b/starboard/shared/stub/file_seek.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" int64_t SbFileSeek(SbFile file, SbFileWhence whence, int64_t offset) { return 0; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_truncate.cc b/starboard/shared/stub/file_truncate.cc index b65a8cce8e41..21c63ca67f52 100644 --- a/starboard/shared/stub/file_truncate.cc +++ b/starboard/shared/stub/file_truncate.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" bool SbFileTruncate(SbFile file, int64_t length) { return false; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/file_write.cc b/starboard/shared/stub/file_write.cc index d6e785874be8..35e1314a784c 100644 --- a/starboard/shared/stub/file_write.cc +++ b/starboard/shared/stub/file_write.cc @@ -12,8 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" int SbFileWrite(SbFile file, const char* data, int size) { return 0; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/stub/player_get_audio_configuration.cc b/starboard/shared/stub/player_get_audio_configuration.cc index 3c685f150a39..78b44f7c5c0b 100644 --- a/starboard/shared/stub/player_get_audio_configuration.cc +++ b/starboard/shared/stub/player_get_audio_configuration.cc @@ -14,9 +14,13 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 + bool SbPlayerGetAudioConfiguration( SbPlayer player, int index, SbMediaAudioConfiguration* out_audio_configuration) { return false; } + +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/stub/player_get_info.cc b/starboard/shared/stub/player_get_info.cc index 04c38acde0ca..f368ccbd9412 100644 --- a/starboard/shared/stub/player_get_info.cc +++ b/starboard/shared/stub/player_get_info.cc @@ -14,4 +14,8 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerGetInfo(SbPlayer player, SbPlayerInfo* out_player_info) {} +#else // SB_API_VERSION >= 15 +void SbPlayerGetInfo2(SbPlayer player, SbPlayerInfo2* out_player_info) {} +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/stub/player_seek.cc b/starboard/shared/stub/player_seek.cc index ad5c70435951..43acbe2b842b 100644 --- a/starboard/shared/stub/player_seek.cc +++ b/starboard/shared/stub/player_seek.cc @@ -14,4 +14,8 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerSeek(SbPlayer player, int64_t seek_to_timestamp, int ticket) {} +#else // SB_API_VERSION >= 15 +void SbPlayerSeek2(SbPlayer player, int64_t seek_to_timestamp, int ticket) {} +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/stub/player_write_samples.cc b/starboard/shared/stub/player_write_samples.cc index a732cf7ca557..ef08d173b896 100644 --- a/starboard/shared/stub/player_write_samples.cc +++ b/starboard/shared/stub/player_write_samples.cc @@ -14,7 +14,12 @@ #include "starboard/player.h" +#if SB_API_VERSION >= 15 void SbPlayerWriteSamples(SbPlayer player, +#else // SB_API_VERSION >= 15 +void SbPlayerWriteSample2(SbPlayer player, +#endif // SB_API_VERSION >= 15 SbMediaType sample_type, const SbPlayerSampleInfo* sample_infos, - int number_of_sample_infos) {} + int number_of_sample_infos) { +} diff --git a/starboard/shared/stub/system_get_device_type.cc b/starboard/shared/stub/system_get_device_type.cc new file mode 100644 index 000000000000..00ac8d3194a6 --- /dev/null +++ b/starboard/shared/stub/system_get_device_type.cc @@ -0,0 +1,23 @@ +// Copyright 2016 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + return kSbSystemDeviceTypeUnknown; +} + +#endif diff --git a/starboard/shared/uwp/application_uwp.cc b/starboard/shared/uwp/application_uwp.cc index 85fa13ad7084..472a03878e43 100644 --- a/starboard/shared/uwp/application_uwp.cc +++ b/starboard/shared/uwp/application_uwp.cc @@ -231,7 +231,7 @@ std::vector ParseStarboardUri(const std::string& uri) { } void AddArgumentsFromFile(const char* path, std::vector* args) { - ScopedFile file(path, kSbFileOpenOnly | kSbFileRead); + ScopedFile file(path, 0); if (!file.IsValid()) { SB_LOG(INFO) << path << " is not valid for arguments."; return; @@ -719,8 +719,7 @@ ref class App sealed : public IFrameworkView { std::stringstream ss; ss << platformStringToString( Windows::Storage::ApplicationData::Current->LocalCacheFolder->Path); - ss << "\\" - << "" << command_line->GetSwitchValue(kLogPathSwitch); + ss << "\\" << "" << command_line->GetSwitchValue(kLogPathSwitch); std::string full_path_log_file = ss.str(); shared::uwp::OpenLogFileWin32(full_path_log_file.c_str()); } else { @@ -1328,10 +1327,16 @@ int InternalMain() { #if defined(COBALT_BUILD_TYPE_GOLD) // Early exit for gold builds on desktop as a security measure. +#if SB_API_VERSION < 15 + if (SbSystemGetDeviceType() == kSbSystemDeviceTypeDesktopPC) { + return main_return_value; + } +#else if (GetSystemPropertyString(kSbSystemPropertyDeviceType) == kSystemDeviceTypeDesktopPC) { return main_return_value; } +#endif #endif // defined(COBALT_BUILD_TYPE_GOLD) shared::win32::RegisterMainThread(); diff --git a/starboard/shared/uwp/application_uwp.h b/starboard/shared/uwp/application_uwp.h index 504ce1a486e9..745b84e8dd81 100644 --- a/starboard/shared/uwp/application_uwp.h +++ b/starboard/shared/uwp/application_uwp.h @@ -54,7 +54,11 @@ class ApplicationUwp : public shared::starboard::Application, public: const float kDefaultScreenRefreshRate = 60.f; +#if SB_API_VERSION >= 15 explicit ApplicationUwp(SbEventHandleCallback sb_event_handle_callback); +#else + ApplicationUwp(); +#endif ~ApplicationUwp() override; static ApplicationUwp* Get() { diff --git a/starboard/shared/uwp/audio_renderer_passthrough.h b/starboard/shared/uwp/audio_renderer_passthrough.h index 53f0447cdb6d..d3c39f9fe4e3 100644 --- a/starboard/shared/uwp/audio_renderer_passthrough.h +++ b/starboard/shared/uwp/audio_renderer_passthrough.h @@ -107,12 +107,12 @@ class AudioRendererPassthrough : public AudioRenderer, double playback_rate_ = 1.0; int64_t seeking_to_time_ = 0; - atomic_bool end_of_stream_written_{false}; - atomic_bool end_of_stream_played_{false}; + std::atomic_bool end_of_stream_written_{false}; + std::atomic_bool end_of_stream_played_{false}; // Use DecodedAudio to store decrypted and formatted encoded audio data. std::queue> pending_inputs_; - atomic_bool can_accept_more_data_; + std::atomic_bool can_accept_more_data_{false}; JobQueue::JobToken process_audio_buffers_job_token_; std::function process_audio_buffers_job_; diff --git a/starboard/shared/uwp/extended_resources_manager.h b/starboard/shared/uwp/extended_resources_manager.h index 78d3fee1d9c8..b00c9525c893 100644 --- a/starboard/shared/uwp/extended_resources_manager.h +++ b/starboard/shared/uwp/extended_resources_manager.h @@ -20,7 +20,6 @@ #include -#include "starboard/common/atomic.h" #include "starboard/common/mutex.h" #include "starboard/common/queue.h" #include "starboard/configuration.h" @@ -85,7 +84,7 @@ class ExtendedResourcesManager { shared::starboard::ThreadChecker thread_checker_; Mutex mutex_; - atomic_bool is_extended_resources_acquired_; + std::atomic_bool is_extended_resources_acquired_{false}; std::atomic_bool is_av1_shader_compiled_ = {false}; std::atomic_bool is_vp9_shader_compiled_ = {false}; @@ -99,7 +98,7 @@ class ExtendedResourcesManager { // This is set to true when a release of extended resources is requested. // Anything delaying the release should be expedited when this is set. - atomic_bool pending_extended_resources_release_; + std::atomic_bool pending_extended_resources_release_{false}; // This condition variable is used to synchronize changes to // is_extended_resources_acquired_. diff --git a/starboard/shared/uwp/microphone_impl.cc b/starboard/shared/uwp/microphone_impl.cc index 8b5eb24588f9..5721f011c126 100644 --- a/starboard/shared/uwp/microphone_impl.cc +++ b/starboard/shared/uwp/microphone_impl.cc @@ -21,13 +21,13 @@ // C++ headers. #include +#include #include #include #include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/semaphore.h" @@ -492,7 +492,7 @@ class MicrophoneImpl : public SbMicrophonePrivate { // Singleton access is required by the microphone interface as specified by // nplb. const SbMicrophoneId kSingletonId = reinterpret_cast(0x1); -starboard::atomic_pointer s_singleton_pointer; +std::atomic s_singleton_pointer{nullptr}; } // namespace. diff --git a/starboard/shared/uwp/player_components_factory.cc b/starboard/shared/uwp/player_components_factory.cc index a02392f66195..4ead7137e009 100644 --- a/starboard/shared/uwp/player_components_factory.cc +++ b/starboard/shared/uwp/player_components_factory.cc @@ -219,11 +219,18 @@ class PlayerComponentsFactory : public PlayerComponents::Factory { } #if !SB_HAS(GPU_DECODERS_ON_DESKTOP) +#if SB_API_VERSION < 15 + if (SbSystemGetDeviceType() == kSbSystemDeviceTypeDesktopPC) { + SB_LOG(WARNING) << "GPU decoder disabled on Desktop."; + return false; + } +#else if (GetSystemPropertyString(kSbSystemPropertyDeviceType) == kSystemDeviceTypeDesktopPC) { SB_LOG(WARNING) << "GPU decoder disabled on Desktop."; return false; } +#endif #endif // !SB_HAS(GPU_DECODERS_ON_DESKTOP) if (video_codec != kSbMediaVideoCodecVp9 && video_codec != kSbMediaVideoCodecAv1) { diff --git a/starboard/shared/uwp/system_get_device_type.cc b/starboard/shared/uwp/system_get_device_type.cc new file mode 100644 index 000000000000..e1b941b08e16 --- /dev/null +++ b/starboard/shared/uwp/system_get_device_type.cc @@ -0,0 +1,42 @@ +// Copyright 2017 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#include + +#include "starboard/common/log.h" +#include "starboard/shared/win32/wchar_utils.h" + +using Windows::System::Profile::AnalyticsInfo; +using Windows::System::Profile::AnalyticsVersionInfo; + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + AnalyticsVersionInfo ^ version_info = AnalyticsInfo::VersionInfo; + std::string family = starboard::shared::win32::platformStringToString( + version_info->DeviceFamily); + + if (family.compare("Windows.Desktop") == 0) { + return kSbSystemDeviceTypeDesktopPC; + } + if (family.compare("Windows.Xbox") == 0) { + return kSbSystemDeviceTypeGameConsole; + } + SB_NOTREACHED(); + return kSbSystemDeviceTypeUnknown; +} + +#endif diff --git a/starboard/shared/uwp/system_get_property.cc b/starboard/shared/uwp/system_get_property.cc index 253178967d7a..53baad1ed69f 100644 --- a/starboard/shared/uwp/system_get_property.cc +++ b/starboard/shared/uwp/system_get_property.cc @@ -337,8 +337,10 @@ bool SbSystemGetProperty(SbSystemPropertyId property_id, return CopyStringAndTestIfSuccess(out_value, value_length, advertising_id.empty() ? "1" : "0"); } +#if SB_API_VERSION >= 15 case kSbSystemPropertyDeviceType: return GetDeviceType(out_value, value_length); +#endif default: SB_DLOG(WARNING) << __FUNCTION__ << ": Unrecognized property: " << property_id; diff --git a/starboard/shared/uwp/wasapi_audio.cc b/starboard/shared/uwp/wasapi_audio.cc index 149da359d01d..679aacc4a47c 100644 --- a/starboard/shared/uwp/wasapi_audio.cc +++ b/starboard/shared/uwp/wasapi_audio.cc @@ -15,8 +15,8 @@ #include "starboard/shared/uwp/wasapi_audio.h" #include +#include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/once.h" @@ -97,7 +97,7 @@ class DefaultAudioRenderParams { } private: - atomic_bool is_dirty_{true}; + std::atomic_bool is_dirty_{true}; Mutex mutex_; int cached_bitrate_ = 0; int cached_channels_ = 0; diff --git a/starboard/shared/uwp/wasapi_audio_sink.h b/starboard/shared/uwp/wasapi_audio_sink.h index 0755a12d1757..c846f3476deb 100644 --- a/starboard/shared/uwp/wasapi_audio_sink.h +++ b/starboard/shared/uwp/wasapi_audio_sink.h @@ -19,11 +19,11 @@ #include #include +#include #include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/log.h" #include "starboard/common/mutex.h" #include "starboard/common/ref_counted.h" @@ -156,9 +156,9 @@ class WASAPIAudioSink { const int kAc3BufferSizeInFrames = 1536; const int kEac3BufferSizeInFrames = 6144; - atomic_bool paused_{false}; - atomic_double playback_rate_{0.0}; - atomic_double volume_{0.0}; + std::atomic_bool paused_{false}; + std::atomic playback_rate_{0.0}; + std::atomic volume_{0.0}; double current_volume_ = 0.0; bool was_playing_ = false; diff --git a/starboard/shared/uwp/watchdog_log.cc b/starboard/shared/uwp/watchdog_log.cc index 207ed111b92d..5b6f745f5076 100644 --- a/starboard/shared/uwp/watchdog_log.cc +++ b/starboard/shared/uwp/watchdog_log.cc @@ -14,6 +14,7 @@ #include "starboard/shared/uwp/watchdog_log.h" +#include #include #include @@ -47,12 +48,9 @@ class WatchDogThread : public Thread { void Run() override { static const int64_t kSleepTime = 250'000; // 250ms int counter = 0; - bool created_ok = false; - SbFileError out_error = kSbFileOk; - SbFile file_handle = - SbFileOpen(file_path_.c_str(), kSbFileCreateAlways | kSbFileWrite, - &created_ok, &out_error); - if (!created_ok) { + int file_handle = open(file_path_.c_str(), O_CREAT | O_TRUNC | O_WRONLY, + S_IRUSR | S_IWUSR); + if (!IsValid(file_handle)) { SB_LOG(ERROR) << "Could not create watchdog file " << file_path_; return; } @@ -61,17 +59,16 @@ class WatchDogThread : public Thread { ss << "alive: " << counter++ << "\n"; std::string str = ss.str(); int result = - SbFileWrite(file_handle, str.c_str(), static_cast(str.size())); + write(file_handle, str.c_str(), static_cast(str.size())); RecordFileWriteStat(result); - SbFileFlush(file_handle); + fsync(file_handle); } const char kDone[] = "done\n"; - int result = - SbFileWrite(file_handle, kDone, static_cast(strlen(kDone))); + int result = write(file_handle, kDone, static_cast(strlen(kDone))); RecordFileWriteStat(result); - SbFileFlush(file_handle); + fsync(file_handle); usleep(50'000); - bool closed = SbFileClose(file_handle); + bool closed = !close(file_handle); SB_LOG_IF(ERROR, closed) << "Could not close file " << file_path_; } diff --git a/starboard/shared/widevine/drm_system_widevine.h b/starboard/shared/widevine/drm_system_widevine.h index 146557313e2b..257de6558cf0 100644 --- a/starboard/shared/widevine/drm_system_widevine.h +++ b/starboard/shared/widevine/drm_system_widevine.h @@ -15,13 +15,14 @@ #ifndef STARBOARD_SHARED_WIDEVINE_DRM_SYSTEM_WIDEVINE_H_ #define STARBOARD_SHARED_WIDEVINE_DRM_SYSTEM_WIDEVINE_H_ +#include #include #include #include #include #include -#include "starboard/common/atomic.h" +#include "starboard/common/mutex.h" #include "starboard/common/optional.h" #include "starboard/mutex.h" #include "starboard/shared/starboard/drm/drm_system_internal.h" @@ -199,7 +200,7 @@ class DrmSystemWidevine : public SbDrmSystemPrivate, int maximum_number_of_session_updates_ = std::numeric_limits::max(); #endif // !defined(COBALT_BUILD_TYPE_GOLD) - atomic_bool first_update_session_received_{false}; + std::atomic_bool first_update_session_received_{false}; }; } // namespace widevine diff --git a/starboard/shared/win32/application_win32.cc b/starboard/shared/win32/application_win32.cc index 356c6a698b0d..0e337f06d48b 100644 --- a/starboard/shared/win32/application_win32.cc +++ b/starboard/shared/win32/application_win32.cc @@ -119,10 +119,15 @@ namespace starboard { namespace shared { namespace win32 { +#if SB_API_VERSION >= 15 ApplicationWin32::ApplicationWin32( SbEventHandleCallback sb_event_handle_callback) : localized_strings_(SbSystemGetLocaleId()), QueueApplication(sb_event_handle_callback) {} +#else +ApplicationWin32::ApplicationWin32() + : localized_strings_(SbSystemGetLocaleId()) {} +#endif // SB_API_VERSION >= 15 ApplicationWin32::~ApplicationWin32() {} SbWindow ApplicationWin32::CreateWindowForWin32( diff --git a/starboard/shared/win32/application_win32.h b/starboard/shared/win32/application_win32.h index f0ebcef9b46a..52955d044c71 100644 --- a/starboard/shared/win32/application_win32.h +++ b/starboard/shared/win32/application_win32.h @@ -37,7 +37,11 @@ namespace win32 { class ApplicationWin32 : public starboard::QueueApplication { public: +#if SB_API_VERSION >= 15 explicit ApplicationWin32(SbEventHandleCallback sb_event_handle_callback); +#else + ApplicationWin32(); +#endif // SB_API_VERSION >= 15 ~ApplicationWin32() override; static ApplicationWin32* Get() { diff --git a/starboard/shared/win32/audio_decoder_thread.cc b/starboard/shared/win32/audio_decoder_thread.cc index f1bd9497fd6b..15e77d620bd0 100644 --- a/starboard/shared/win32/audio_decoder_thread.cc +++ b/starboard/shared/win32/audio_decoder_thread.cc @@ -75,7 +75,7 @@ bool AudioDecoderThread::QueueInput(const scoped_refptr& buffer) { } // increment() returns the previous value. - size_t element_count = processing_elements_.increment() + 1; + size_t element_count = processing_elements_++ + 1; semaphore_.Put(); return element_count < kMaxProcessingElements; } diff --git a/starboard/shared/win32/audio_decoder_thread.h b/starboard/shared/win32/audio_decoder_thread.h index 34567135a2e6..3ede570fb25e 100644 --- a/starboard/shared/win32/audio_decoder_thread.h +++ b/starboard/shared/win32/audio_decoder_thread.h @@ -15,10 +15,10 @@ #ifndef STARBOARD_SHARED_WIN32_AUDIO_DECODER_THREAD_H_ #define STARBOARD_SHARED_WIN32_AUDIO_DECODER_THREAD_H_ +#include #include #include -#include "starboard/common/atomic.h" #include "starboard/common/ref_counted.h" #include "starboard/common/semaphore.h" #include "starboard/common/thread.h" @@ -60,7 +60,7 @@ class AudioDecoderThread : private Thread { std::deque > input_buffer_queue_; ::starboard::Mutex input_buffer_queue_mutex_; - atomic_int32_t processing_elements_; + std::atomic processing_elements_{0}; Semaphore semaphore_; }; diff --git a/starboard/shared/win32/file_can_open.cc b/starboard/shared/win32/file_can_open.cc index 8f830b250e3e..7744b103eec5 100644 --- a/starboard/shared/win32/file_can_open.cc +++ b/starboard/shared/win32/file_can_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -52,3 +54,5 @@ bool SbFileCanOpen(const char* path, int flags) { return can_open; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_close.cc b/starboard/shared/win32/file_close.cc index afd99ae3c9c5..fa47181459dc 100644 --- a/starboard/shared/win32/file_close.cc +++ b/starboard/shared/win32/file_close.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -36,3 +38,5 @@ bool SbFileClose(SbFile file) { return success; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_delete.cc b/starboard/shared/win32/file_delete.cc index 2d5aa0cba3bd..d20cd80ed217 100644 --- a/starboard/shared/win32/file_delete.cc +++ b/starboard/shared/win32/file_delete.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -37,3 +39,5 @@ bool SbFileDelete(const char* path) { return DeleteFileW(path_wstring.c_str()) || RemoveDirectoryW(path_wstring.c_str()); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_exists.cc b/starboard/shared/win32/file_exists.cc index 3072769ecbea..70093daf6e29 100644 --- a/starboard/shared/win32/file_exists.cc +++ b/starboard/shared/win32/file_exists.cc @@ -52,4 +52,5 @@ bool SbFileExists(const char* path) { return PathEndsWith(path_wstring, find_data.cFileName); } -#endif + +#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/win32/file_flush.cc b/starboard/shared/win32/file_flush.cc index c42e69e5db98..ad566da0cc73 100644 --- a/starboard/shared/win32/file_flush.cc +++ b/starboard/shared/win32/file_flush.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -26,3 +28,5 @@ bool SbFileFlush(SbFile file) { return FlushFileBuffers(file->file_handle); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_get_info.cc b/starboard/shared/win32/file_get_info.cc index 6a3bff46d956..f4176e5b014f 100644 --- a/starboard/shared/win32/file_get_info.cc +++ b/starboard/shared/win32/file_get_info.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -56,3 +58,5 @@ bool SbFileGetInfo(SbFile file, SbFileInfo* out_info) { return true; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_open.cc b/starboard/shared/win32/file_open.cc index 2aa61824e32d..d632c234a363 100644 --- a/starboard/shared/win32/file_open.cc +++ b/starboard/shared/win32/file_open.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include "starboard/shared/win32/file_internal.h" @@ -39,3 +41,5 @@ SbFile SbFileOpen(const char* path, return new SbFilePrivate(file_handle); } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_read.cc b/starboard/shared/win32/file_read.cc index e0efce44825e..f8415ae71765 100644 --- a/starboard/shared/win32/file_read.cc +++ b/starboard/shared/win32/file_read.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -45,3 +47,5 @@ int SbFileRead(SbFile file, char* data, int size) { return number_bytes_read; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_seek.cc b/starboard/shared/win32/file_seek.cc index 640059430da7..117df70b36a7 100644 --- a/starboard/shared/win32/file_seek.cc +++ b/starboard/shared/win32/file_seek.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -36,3 +38,5 @@ int64_t SbFileSeek(SbFile file, SbFileWhence whence, int64_t offset) { return new_file_pointer.QuadPart; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_truncate.cc b/starboard/shared/win32/file_truncate.cc index 7e77ab97ca38..21fef69fa87e 100644 --- a/starboard/shared/win32/file_truncate.cc +++ b/starboard/shared/win32/file_truncate.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -100,3 +102,5 @@ bool SbFileTruncate(SbFile file, int64_t length) { return return_value; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/file_write.cc b/starboard/shared/win32/file_write.cc index 6e56f68f9ffc..b95460c8b0f6 100644 --- a/starboard/shared/win32/file_write.cc +++ b/starboard/shared/win32/file_write.cc @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +#if SB_API_VERSION < 17 + #include "starboard/file.h" #include @@ -40,3 +42,5 @@ int SbFileWrite(SbFile file, const char* data, int size) { return bytes_written; } + +#endif // SB_API_VERSION < 17 diff --git a/starboard/shared/win32/log_file_impl.cc b/starboard/shared/win32/log_file_impl.cc index 022f7d259880..9158e6e70ec4 100644 --- a/starboard/shared/win32/log_file_impl.cc +++ b/starboard/shared/win32/log_file_impl.cc @@ -14,7 +14,9 @@ #include "starboard/shared/win32/log_file_impl.h" +#include #include +#include #include #include @@ -32,15 +34,15 @@ namespace { pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; -SbFile log_file = kSbFileInvalid; +int log_file = -1; // SbMutex is not reentrant, so factor out close log file functionality for use // by other functions. void CloseLogFileWithoutLock() { - if (SbFileIsValid(log_file)) { - SbFileFlush(log_file); - SbFileClose(log_file); - log_file = kSbFileInvalid; + if (starboard::IsValid(log_file)) { + fsync(log_file); + close(log_file); + log_file = -1; } } @@ -57,8 +59,8 @@ void CloseLogFile() { } void OpenLogInCacheDirectory(const char* log_file_name, int creation_flags) { - SB_DCHECK((creation_flags & kSbFileOpenAlways) || - (creation_flags & kSbFileCreateAlways)); + SB_DCHECK((creation_flags & O_CREAT) || + ((creation_flags & O_CREAT) && (creation_flags & O_TRUNC))); SB_DCHECK(strlen(log_file_name) != 0); SB_DCHECK(strchr(log_file_name, kSbFileSepChar) == nullptr); std::vector out_path(kSbFileMaxPath + 1); @@ -92,8 +94,8 @@ void OpenLogFile(const char* path, const int creation_flags) { pthread_mutex_lock(&log_mutex); CloseLogFileWithoutLock(); if ((path != nullptr) && (path[0] != '\0')) { - log_file = SbFileOpen(path, flags, nullptr, nullptr); - SB_DCHECK(SbFileIsValid(log_file)); + log_file = open(path, flags, S_IRUSR | S_IWUSR); + SB_DCHECK(starboard::IsValid(log_file)); } pthread_mutex_unlock(&log_mutex); @@ -104,16 +106,16 @@ void WriteToLogFile(const char* text, const int text_length) { return; } pthread_mutex_lock(&log_mutex); - if (!SbFileIsValid(log_file)) { + if (!starboard::IsValid(log_file)) { pthread_mutex_unlock(&log_mutex); return; } - int bytes_written = SbFileWriteAll(log_file, text, text_length); + int bytes_written = starboard::WriteAll(log_file, text, text_length); RecordFileWriteStat(bytes_written); SB_DCHECK(text_length == bytes_written); - SbFileFlush(log_file); + fsync(log_file); pthread_mutex_unlock(&log_mutex); } diff --git a/starboard/shared/win32/socket_internal.h b/starboard/shared/win32/socket_internal.h index c51eed06411b..b437feadf94c 100644 --- a/starboard/shared/win32/socket_internal.h +++ b/starboard/shared/win32/socket_internal.h @@ -17,8 +17,8 @@ #include #include +#include -#include "starboard/common/atomic.h" #include "starboard/common/socket.h" #include "starboard/shared/internal_only.h" #include "starboard/shared/win32/auto_event_handle.h" @@ -43,7 +43,6 @@ struct SbSocketPrivate { protocol(protocol), socket_handle(handle), socket_event(WSA_INVALID_EVENT), - writable(0), error(kSbSocketOk), waiter(kSbSocketWaiterInvalid), bound_to(bound_to) {} @@ -69,7 +68,7 @@ struct SbSocketPrivate { // edge-triggered, unlike other events. // // See MSDN documentation for WSAEventSelect FD_WRITE for more info. - starboard::atomic_bool writable; + std::atomic_bool writable{false}; // The last error that occurred on this socket, or kSbSocketOk. SbSocketError error; diff --git a/starboard/shared/win32/starboard_main.cc b/starboard/shared/win32/starboard_main.cc index 0b8ae37e1a99..372d797a982b 100644 --- a/starboard/shared/win32/starboard_main.cc +++ b/starboard/shared/win32/starboard_main.cc @@ -73,9 +73,21 @@ extern "C" int StarboardMain(int argc, char** argv) { SB_DCHECK(SUCCEEDED(hr)); WaitForNetLogIfNecessary(CommandLine(argc, argv)); +#if SB_API_VERSION >= 15 return SbRunStarboardMain(argc, argv, SbEventHandle); +#else + ApplicationWin32 application; + // This will run the message loop. + const int main_return_value = application.Run(argc, argv); + NetLogFlushThenClose(); + + MFShutdown(); + WSACleanup(); + return main_return_value; +#endif // SB_API_VERSION >= 15 } +#if SB_API_VERSION >= 15 int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { ApplicationWin32 application(callback); // This will run the message loop. @@ -86,3 +98,4 @@ int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { WSACleanup(); return main_return_value; } +#endif // SB_API_VERSION >= 15 diff --git a/starboard/shared/win32/storage_write_record.cc b/starboard/shared/win32/storage_write_record.cc index 012d94bb4b72..a83a955673c1 100644 --- a/starboard/shared/win32/storage_write_record.cc +++ b/starboard/shared/win32/storage_write_record.cc @@ -14,15 +14,17 @@ #include "starboard/common/storage.h" +#include +#include #include #include #include +#include "starboard/common/file.h" #include "starboard/common/log.h" #include "starboard/common/string.h" #include "starboard/configuration_constants.h" -#include "starboard/file.h" #include "starboard/shared/starboard/file_storage/storage_internal.h" #include "starboard/shared/win32/file_internal.h" #include "starboard/shared/win32/wchar_utils.h" @@ -48,25 +50,23 @@ bool SbStorageWriteRecord(SbStorageRecord record, kSbFileMaxPath); starboard::strlcat(temp_file_path.data(), kTempFileSuffix, kSbFileMaxPath); - SbFileError error; - SbFile temp_file = SbFileOpen( - temp_file_path.data(), kSbFileCreateAlways | kSbFileWrite | kSbFileRead, - NULL, &error); - if (error != kSbFileOk) { + int temp_file = open(temp_file_path.data(), O_CREAT | O_TRUNC | O_RDWR, + S_IRUSR | S_IWUSR); + if (!starboard::IsValid(temp_file)) { return false; } - SbFileTruncate(temp_file, 0); + ftruncate(temp_file, 0); const char* source = data; int64_t to_write = data_size; while (to_write > 0) { int to_write_max = static_cast(std::min(to_write, static_cast(kSbInt32Max))); - int bytes_written = SbFileWrite(temp_file, source, to_write_max); + int bytes_written = write(temp_file, source, to_write_max); if (bytes_written < 0) { - SbFileClose(temp_file); - SbFileDelete(temp_file_path.data()); + close(temp_file); + unlink(temp_file_path.data()); return false; } @@ -74,15 +74,15 @@ bool SbStorageWriteRecord(SbStorageRecord record, to_write -= bytes_written; } - SbFileFlush(temp_file); + fsync(temp_file); - if (SbFileIsValid(record->file) && !SbFileClose(record->file)) { + if (starboard::IsValid(record->file) && close(record->file)) { return false; } - record->file = kSbFileInvalid; + record->file = -1; - if (!SbFileClose(temp_file)) { + if (close(temp_file)) { return false; } @@ -96,9 +96,8 @@ bool SbStorageWriteRecord(SbStorageRecord record, NULL, 0, NULL, NULL) == 0) { return false; } - SbFile new_record_file = - SbFileOpen(original_file_path.data(), - kSbFileOpenOnly | kSbFileWrite | kSbFileRead, NULL, NULL); + int new_record_file = + open(original_file_path.data(), O_RDWR, S_IRUSR | S_IWUSR); record->file = new_record_file; return true; diff --git a/starboard/shared/win32/system_get_device_type.cc b/starboard/shared/win32/system_get_device_type.cc new file mode 100644 index 000000000000..5e5a4647c717 --- /dev/null +++ b/starboard/shared/win32/system_get_device_type.cc @@ -0,0 +1,28 @@ +// Copyright 2017 The Cobalt Authors. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "starboard/system.h" + +#include + +#include "starboard/common/log.h" +#include "starboard/shared/win32/wchar_utils.h" + +#if SB_API_VERSION < 15 + +SbSystemDeviceType SbSystemGetDeviceType() { + return kSbSystemDeviceTypeDesktopPC; +} + +#endif diff --git a/starboard/shared/win32/system_get_property.cc b/starboard/shared/win32/system_get_property.cc index d9cda3dbcf6f..76eb1f05fcb9 100644 --- a/starboard/shared/win32/system_get_property.cc +++ b/starboard/shared/win32/system_get_property.cc @@ -66,9 +66,13 @@ bool SbSystemGetProperty(SbSystemPropertyId property_id, return CopyStringAndTestIfSuccess( out_value, value_length, starboard::GetEnvironment("COBALT_LIMIT_AD_TRACKING").c_str()); + +#if SB_API_VERSION >= 15 case kSbSystemPropertyDeviceType: return CopyStringAndTestIfSuccess(out_value, value_length, starboard::kSystemDeviceTypeDesktopPC); +#endif + default: SB_DLOG(WARNING) << __FUNCTION__ << ": Unrecognized property: " << property_id; diff --git a/starboard/shared/win32/win32_audio_decoder.cc b/starboard/shared/win32/win32_audio_decoder.cc index 4c297841c4d3..d550cd7bfed2 100644 --- a/starboard/shared/win32/win32_audio_decoder.cc +++ b/starboard/shared/win32/win32_audio_decoder.cc @@ -68,7 +68,6 @@ class AbstractWin32AudioDecoderImpl : public AbstractWin32AudioDecoder { audio_frame_fmt_(audio_frame_fmt), sample_type_(sample_type), number_of_channels_(audio_stream_info.number_of_channels), - heaac_detected_(false), expected_buffer_size_( GetExpectedBufferSize(codec_, audio_stream_info.number_of_channels)) { @@ -234,7 +233,7 @@ class AbstractWin32AudioDecoderImpl : public AbstractWin32AudioDecoder { std::unique_ptr impl_; std::queue output_queue_; uint16_t number_of_channels_; - atomic_bool heaac_detected_; + std::atomic_bool heaac_detected_{false}; int samples_per_second_; const size_t expected_buffer_size_; }; diff --git a/starboard/shared/x11/application_x11.cc b/starboard/shared/x11/application_x11.cc index c6a838efa5d1..1e1f5f4226b6 100644 --- a/starboard/shared/x11/application_x11.cc +++ b/starboard/shared/x11/application_x11.cc @@ -693,11 +693,17 @@ int ErrorHandler(Display* display, XErrorEvent* event) { using shared::starboard::player::filter::CpuVideoFrame; +#if SB_API_VERSION >= 15 ApplicationX11::ApplicationX11(SbEventHandleCallback sb_event_handle_callback) +#else +ApplicationX11::ApplicationX11() +#endif // SB_API_VERSION >= 15 : wake_up_atom_(None), wm_delete_atom_(None), wm_change_state_atom_(None), +#if SB_API_VERSION >= 15 QueueApplication(sb_event_handle_callback), +#endif // SB_API_VERSION >= 15 composite_event_id_(kSbEventIdInvalid), display_(NULL), paste_buffer_key_release_pending_(false) { diff --git a/starboard/shared/x11/application_x11.h b/starboard/shared/x11/application_x11.h index 5d8f715a3e57..6182371c3aac 100644 --- a/starboard/shared/x11/application_x11.h +++ b/starboard/shared/x11/application_x11.h @@ -38,7 +38,11 @@ namespace x11 { // This application engine combines the generic queue with the X11 event queue. class ApplicationX11 : public shared::starboard::QueueApplication { public: +#if SB_API_VERSION >= 15 explicit ApplicationX11(SbEventHandleCallback sb_event_handle_callback); +#else + ApplicationX11(); +#endif // SB_API_VERSION >= 15 ~ApplicationX11() override; static ApplicationX11* Get() { diff --git a/starboard/stub/BUILD.gn b/starboard/stub/BUILD.gn index 0fe618efb038..181951e2346b 100644 --- a/starboard/stub/BUILD.gn +++ b/starboard/stub/BUILD.gn @@ -198,6 +198,7 @@ static_library("stub_sources") { "//starboard/shared/stub/system_break_into_debugger.cc", "//starboard/shared/stub/system_clear_last_error.cc", "//starboard/shared/stub/system_egl.cc", + "//starboard/shared/stub/system_get_device_type.cc", "//starboard/shared/stub/system_get_error_string.cc", "//starboard/shared/stub/system_get_last_error.cc", "//starboard/shared/stub/system_get_locale_id.cc", diff --git a/starboard/stub/application_stub.cc b/starboard/stub/application_stub.cc index 5d48238a38b7..7aeb224b092c 100644 --- a/starboard/stub/application_stub.cc +++ b/starboard/stub/application_stub.cc @@ -20,8 +20,12 @@ namespace starboard { namespace stub { +#if SB_API_VERSION >= 15 ApplicationStub::ApplicationStub(SbEventHandleCallback sb_event_handle_callback) : QueueApplication(sb_event_handle_callback) {} +#else +ApplicationStub::ApplicationStub() {} +#endif // SB_API_VERSION >= 15 ApplicationStub::~ApplicationStub() {} diff --git a/starboard/stub/application_stub.h b/starboard/stub/application_stub.h index b2aeb84d23e4..72a8cd2ade70 100644 --- a/starboard/stub/application_stub.h +++ b/starboard/stub/application_stub.h @@ -27,7 +27,11 @@ namespace stub { // Stub application engine using the generic queue and a stub implementation. class ApplicationStub : public shared::starboard::QueueApplication { public: +#if SB_API_VERSION >= 15 explicit ApplicationStub(SbEventHandleCallback sb_event_handle_callback); +#else + ApplicationStub(); +#endif // SB_API_VERSION >= 15 ~ApplicationStub() override; diff --git a/starboard/stub/main.cc b/starboard/stub/main.cc index 8bcb60f82171..48d568d4c318 100644 --- a/starboard/stub/main.cc +++ b/starboard/stub/main.cc @@ -16,10 +16,17 @@ #include "starboard/stub/application_stub.h" int main(int argc, char** argv) { +#if SB_API_VERSION >= 15 return SbRunStarboardMain(argc, argv, SbEventHandle); +#else + starboard::stub::ApplicationStub application; + return application.Run(argc, argv); +#endif // SB_API_VERSION >= 15 } +#if SB_API_VERSION >= 15 int SbRunStarboardMain(int argc, char** argv, SbEventHandleCallback callback) { starboard::stub::ApplicationStub application(callback); return application.Run(argc, argv); } +#endif // SB_API_VERSION >= 15 diff --git a/starboard/system.h b/starboard/system.h index 5f7802a725e7..ba1bfb38759f 100644 --- a/starboard/system.h +++ b/starboard/system.h @@ -125,11 +125,48 @@ typedef enum SbSystemPropertyId { // a true value. Corresponds to 'lmt' field. kSbSystemPropertyLimitAdTracking, +#if SB_API_VERSION >= 15 // Type of the device, e.g. such as "TV", "STB", "OTT" // Please see Youtube Technical requirements for a full list of allowed values kSbSystemPropertyDeviceType, +#endif } SbSystemPropertyId; +#if SB_API_VERSION < 15 +// Enumeration of device types. +typedef enum SbSystemDeviceType { + // Blue-ray Disc Player (BDP). + kSbSystemDeviceTypeBlueRayDiskPlayer, + + // A relatively high-powered TV device used primarily for playing games. + kSbSystemDeviceTypeGameConsole, + + // Over the top (OTT) devices stream content via the Internet over another + // type of network, e.g. cable or satellite. + kSbSystemDeviceTypeOverTheTopBox, + + // Set top boxes (STBs) stream content primarily over cable or satellite. + // Some STBs can also stream OTT content via the Internet. + kSbSystemDeviceTypeSetTopBox, + + // A Smart TV is a TV that can directly run applications that stream OTT + // content via the Internet. + kSbSystemDeviceTypeTV, + + // Desktop PC. + kSbSystemDeviceTypeDesktopPC, + + // An Android TV Device. + kSbSystemDeviceTypeAndroidTV, + + // A wall video projector. + kSbSystemDeviceTypeVideoProjector, + + // Unknown device. + kSbSystemDeviceTypeUnknown, +} SbSystemDeviceType; +#endif // SB_API_VERSION < 15 + // Runtime capabilities are boolean properties of a platform that can't be // determined at compile-time. They may vary from device to device, but they // will not change over the course of a single execution. They often specify @@ -247,6 +284,11 @@ SB_EXPORT int64_t SbSystemGetTotalGPUMemory(); // SbSystemHasCapability(kSbSystemCapabilityCanQueryGPUMemoryStats) is |true|. SB_EXPORT int64_t SbSystemGetUsedGPUMemory(); +#if SB_API_VERSION < 15 +// Returns the type of the device. +SB_EXPORT SbSystemDeviceType SbSystemGetDeviceType(); +#endif + // Returns if the device is disconnected from network. "Disconnected" is chosen // over connected because disconnection can be determined with more certainty // than connection usually. diff --git a/starboard/win/win32/BUILD.gn b/starboard/win/win32/BUILD.gn index e782e40c58d2..746db846b634 100644 --- a/starboard/win/win32/BUILD.gn +++ b/starboard/win/win32/BUILD.gn @@ -52,6 +52,7 @@ static_library("starboard_platform") { "//starboard/shared/win32/player_components_factory.cc", "//starboard/shared/win32/playready_license.cc", "//starboard/shared/win32/starboard_main.cc", + "//starboard/shared/win32/system_get_device_type.cc", "//starboard/shared/win32/system_get_extensions.cc", "//starboard/shared/win32/system_get_property.cc", "//starboard/shared/win32/system_get_total_cpu_memory.cc", diff --git a/starboard/xb1/BUILD.gn b/starboard/xb1/BUILD.gn index 9cb142af4089..80402c9c3a5b 100644 --- a/starboard/xb1/BUILD.gn +++ b/starboard/xb1/BUILD.gn @@ -126,6 +126,7 @@ static_library("starboard_platform") { "//starboard/shared/uwp/media_is_video_supported.cc", "//starboard/shared/uwp/microphone_impl.cc", "//starboard/shared/uwp/player_components_factory.cc", + "//starboard/shared/uwp/system_get_device_type.cc", "//starboard/shared/uwp/system_get_property.cc", "//starboard/shared/uwp/system_get_total_cpu_memory.cc", "//starboard/shared/uwp/system_get_used_cpu_memory.cc", diff --git a/starboard/xb1/shared/gpu_base_video_decoder.h b/starboard/xb1/shared/gpu_base_video_decoder.h index 3bd9c7a31650..5ef5210ff80b 100644 --- a/starboard/xb1/shared/gpu_base_video_decoder.h +++ b/starboard/xb1/shared/gpu_base_video_decoder.h @@ -25,7 +25,6 @@ #include #include -#include "starboard/common/atomic.h" #include "starboard/common/mutex.h" #include "starboard/common/ref_counted.h" #include "starboard/shared/starboard/decode_target/decode_target_context_runner.h" @@ -205,7 +204,7 @@ class GpuVideoDecoderBase const bool is_10x3_preferred_; int frame_width_; int frame_height_; - atomic_integral decoder_behavior_{kDecodingStopped}; + std::atomic decoder_behavior_{kDecodingStopped}; std::atomic_bool error_occured_ = {false}; // These are platform-specific objects required to create and use a codec. diff --git a/third_party/boringssl/BUILD.gn b/third_party/boringssl/BUILD.gn index 8bf265b2d9ac..84dec32885e0 100644 --- a/third_party/boringssl/BUILD.gn +++ b/third_party/boringssl/BUILD.gn @@ -247,6 +247,7 @@ if (!use_cobalt_customizations) { public -= [ "src/include/openssl/opensslconf.h" ] public_deps = [ "//starboard:starboard_headers_only", + "//starboard/common:file_wrapper", ] configs -= [ "//starboard/build/config:size" ] configs += [ "//starboard/build/config:speed" ] diff --git a/third_party/boringssl/src/crypto/bio/file.c b/third_party/boringssl/src/crypto/bio/file.c index a9614e098f42..f9947d610530 100644 --- a/third_party/boringssl/src/crypto/bio/file.c +++ b/third_party/boringssl/src/crypto/bio/file.c @@ -81,12 +81,23 @@ #define BIO_FLAGS_UPLINK 0 #endif -#if !defined(OPENSSL_SYS_STARBOARD) +#if defined(OPENSSL_SYS_STARBOARD) +#include +#endif // defined(OPENSSL_SYS_STARBOARD) + #include + +#if !defined(OPENSSL_SYS_STARBOARD) #include #endif // !defined(OPENSSL_SYS_STARBOARD) + #include +#if defined(OPENSSL_SYS_STARBOARD) +#include +#include +#endif // defined(OPENSSL_SYS_STARBOARD) + #include #include @@ -96,6 +107,10 @@ #include #endif +#if defined(OPENSSL_SYS_STARBOARD) +#include "starboard/common/file_wrapper.h" +#endif // defined(OPENSSL_SYS_STARBOARD) + #define BIO_FP_READ 0x02 #define BIO_FP_WRITE 0x04 #define BIO_FP_APPEND 0x08 @@ -175,23 +190,27 @@ static FILE *file_fopen(const char *filename, const char *mode) { BIO *BIO_new_file(const char *filename, const char *mode) { BIO *ret = NULL; #if defined(OPENSSL_SYS_STARBOARD) - SbFile sb_file = kSbFileInvalid; - SbFileError error = kSbFileOk; - sb_file = SbFileOpen(filename, SbFileModeStringToFlags(mode), NULL, &error); - if (!SbFileIsValid(sb_file)) { + FilePtr sb_file = (FilePtr)malloc(sizeof(struct FileStruct)); + memset(sb_file, 0, sizeof(struct FileStruct)); + sb_file->fd = open(filename, FileModeStringToFlags(mode), + S_IRUSR | S_IWUSR); + + if (sb_file->fd < 0) { OPENSSL_PUT_SYSTEM_ERROR(); - ERR_add_error_data(5, "SbFileOpen('", filename, "','", mode, "')"); - if (error == kSbFileErrorNotFound) { + ERR_add_error_data(5, "open('", filename, "','", mode, "')"); + if (errno == ENOENT) { OPENSSL_PUT_ERROR(BIO, BIO_R_NO_SUCH_FILE); } else { OPENSSL_PUT_ERROR(BIO, BIO_R_SYS_LIB); } + free(sb_file); return (NULL); } ret = BIO_new(BIO_s_file()); if (ret == NULL) { - SbFileClose(sb_file); + close(sb_file->fd); + free(sb_file); return (NULL); } @@ -267,7 +286,7 @@ static int MS_CALLBACK file_free(BIO *a) { if (a->shutdown) { if ((a->init) && (a->ptr != NULL)) { #if defined(OPENSSL_SYS_STARBOARD) - SbFileClose((SbFile)a->ptr); + close(((FilePtr)a->ptr)->fd); #else // defined(OPENSSL_SYS_STARBOARD) // When this file was Starboardized, uplink support was added to the // non-Starboard code paths. But at this point it's not clear where to find @@ -295,7 +314,7 @@ static int MS_CALLBACK file_read(BIO *b, char *out, int outl) { int ret = 0; if (b->init && (out != NULL)) { #if defined(OPENSSL_SYS_STARBOARD) - ret = SbFileRead((SbFile)b->ptr, out, outl); + ret = read(((FilePtr)b->ptr)->fd, out, outl); if (ret < 0) { OPENSSL_PUT_SYSTEM_ERROR(); OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB); @@ -336,7 +355,7 @@ static int MS_CALLBACK file_write(BIO *b, const char *in, int inl) { if (b->init && (in != NULL)) { #if defined(OPENSSL_SYS_STARBOARD) - ret = SbFileWrite((SbFile)b->ptr, in, inl); + ret = write(((FilePtr)b->ptr)->fd, in, inl); #else // defined(OPENSSL_SYS_STARBOARD) #ifndef NATIVE_TARGET_BUILD if (b->flags & BIO_FLAGS_UPLINK) @@ -361,8 +380,8 @@ static int MS_CALLBACK file_write(BIO *b, const char *in, int inl) { static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { long ret = 1; #if defined(OPENSSL_SYS_STARBOARD) - SbFile fp = (SbFile)b->ptr; - SbFile *fpp; + FilePtr fp = (FilePtr)b->ptr; + FilePtr *fpp; #else // defined(OPENSSL_SYS_STARBOARD) FILE *fp = (FILE *)b->ptr; FILE **fpp; @@ -373,7 +392,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { case BIO_C_FILE_SEEK: case BIO_CTRL_RESET: #if defined(OPENSSL_SYS_STARBOARD) - ret = (long)SbFileSeek((SbFile)b->ptr, num, kSbFileFromBegin); + ret = (long)lseek(((FilePtr)b->ptr)->fd, SEEK_SET, num); #else // defined(OPENSSL_SYS_STARBOARD) #ifndef NATIVE_TARGET_BUILD if (b->flags & BIO_FLAGS_UPLINK) @@ -386,8 +405,8 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { break; case BIO_CTRL_EOF: #if defined(OPENSSL_SYS_STARBOARD) - ret = (SbFileSeek((SbFile)b->ptr, 0, kSbFileFromCurrent) >= - SbFileSeek((SbFile)b->ptr, 0, kSbFileFromEnd) + ret = (lseek(((FilePtr)b->ptr)->fd, SEEK_CUR, 0) >= + lseek(((FilePtr)b->ptr)->fd, SEEK_END, 0) ? 1 : 0); #else // defined(OPENSSL_SYS_STARBOARD) @@ -403,7 +422,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { case BIO_C_FILE_TELL: case BIO_CTRL_INFO: #if defined(OPENSSL_SYS_STARBOARD) - ret = SbFileSeek((SbFile)b->ptr, 0, kSbFileFromCurrent); + ret = lseek(((FilePtr)b->ptr)->fd, SEEK_CUR, 0); #else // defined(OPENSSL_SYS_STARBOARD) #ifndef NATIVE_TARGET_BUILD if (b->flags & BIO_FLAGS_UPLINK) @@ -508,12 +527,11 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { #endif #if defined(OPENSSL_SYS_STARBOARD) { - SbFileError error = kSbFileOk; - fp = SbFileOpen((const char *)ptr, SbFileModeStringToFlags(p), NULL, - &error); - if (!SbFileIsValid(fp)) { + fp->fd = open((const char *)ptr, FileModeStringToFlags(p), + S_IRUSR | S_IWUSR); + if (fp->fd < 0) { OPENSSL_PUT_SYSTEM_ERROR(); - ERR_add_error_data(5, "SbFileOpen('", ptr, "','", p, "')"); + ERR_add_error_data(5, "open('", ptr, "','", p, "')"); OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB); ret = 0; break; @@ -545,10 +563,10 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { break; case BIO_C_GET_FILE_PTR: #if defined(OPENSSL_SYS_STARBOARD) - /* the ptr parameter is actually a SbFile * in this case. */ + /* the ptr parameter is actually a FilePtr * in this case. */ if (ptr != NULL) { - fpp = (SbFile *)ptr; - *fpp = (SbFile)b->ptr; + fpp = (FilePtr *)ptr; + *fpp = (FilePtr)b->ptr; } #else // defined(OPENSSL_SYS_STARBOARD) // the ptr parameter is actually a FILE ** in this case. @@ -566,7 +584,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) { break; case BIO_CTRL_FLUSH: #if defined(OPENSSL_SYS_STARBOARD) - SbFileFlush((SbFile)b->ptr); + fsync(((FilePtr)b->ptr)->fd); #else // defined(OPENSSL_SYS_STARBOARD) #ifndef NATIVE_TARGET_BUILD if (b->flags & BIO_FLAGS_UPLINK) @@ -597,16 +615,16 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size) { buf[0] = '\0'; #if defined(OPENSSL_SYS_STARBOARD) ret = -1; - SbFileInfo info; - SbFileGetInfo((SbFile)bp->ptr, &info); - int64_t current = SbFileSeek((SbFile)bp->ptr, kSbFileFromCurrent, 0); - int64_t remaining = info.size - current; + struct stat info; + fstat(((FilePtr)bp->ptr)->fd, &info); + int64_t current = lseek(((FilePtr)bp->ptr)->fd, 0, SEEK_CUR); + int64_t remaining = info.st_size - current; int64_t max = (size > remaining ? remaining : size - 1); int index = 0; for (; index < max; ++index) { int count = 0; for (;;) { - count = SbFileRead((SbFile)bp->ptr, buf + index, 1); + count = read(((FilePtr)bp->ptr)->fd, buf + index, 1); if (count == 0) { continue; } diff --git a/third_party/freetype/BUILD.gn b/third_party/freetype/BUILD.gn index 95e4c8a90a3c..95947c6f6c57 100644 --- a/third_party/freetype/BUILD.gn +++ b/third_party/freetype/BUILD.gn @@ -153,6 +153,7 @@ source_set("freetype_source") { public_configs = [ ":freetype_config" ] deps = [ + "//starboard/common:file_wrapper", "//third_party/libpng", "//third_party/zlib", ] diff --git a/third_party/freetype/src/include/freetype/config/ftstdlib.h b/third_party/freetype/src/include/freetype/config/ftstdlib.h index 42c0e3f09df6..239858c80ec6 100644 --- a/third_party/freetype/src/include/freetype/config/ftstdlib.h +++ b/third_party/freetype/src/include/freetype/config/ftstdlib.h @@ -110,20 +110,18 @@ #if defined( STARBOARD ) +#include +#include + +#include "starboard/common/file_wrapper.h" #include "starboard/string.h" -#include "starboard/file.h" -#ifndef SEEK_SET -#define SEEK_SET kSbFileFromBegin -#define SEEK_CUR kSbFileFromCurrent -#define SEEK_END kSbFileFromEnd -#endif -#define FT_FILE SbFilePrivate -#define ft_fclose SbFileClose -#define ft_fopen(p, m) SbFileOpen((p), SbFileModeStringToFlags(m), NULL, NULL) -#define ft_fread(b, s, n, f) SbFileRead((f), (char *)(b), (s) * (n)) -#define ft_fseek(f, o, w) SbFileSeek((f), (w), (o)) -#define ft_ftell(f) SbFileSeek((f), kSbFileFromCurrent, 0) +#define FT_FILE FileStruct +#define ft_fclose file_close +#define ft_fopen(p, m) file_open((p), FileModeStringToFlags(m)) +#define ft_fread(b, s, n, f) read((f->fd), (char *)(b), (s) * (n)) +#define ft_fseek(f, o, w) lseek((f->fd), (o), (w)) +#define ft_ftell(f) lseek((f->fd), 0, SEEK_CUR) #define ft_sprintf sprintf #else #include diff --git a/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h b/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h index 1acc6292ec3b..f3ac2e6a6f0e 100644 --- a/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h +++ b/third_party/googletest/src/googletest/include/gtest/internal/gtest-port.h @@ -286,7 +286,7 @@ #if defined __APPLE__ #include #include -#endif +#endif // defined __APPLE__ #include // NOLINT #include @@ -303,6 +303,7 @@ #include #include +#include #include "gtest/internal/custom/gtest-port.h" #include "gtest/internal/gtest-port-arch.h" @@ -2086,7 +2087,7 @@ inline int StrCaseCmp(const char* s1, const char* s2) { #endif //SB_API_VERSION < 16 inline char* StrDup(const char* src) { return strdup(src); } -inline int RmDir(const char* dir) { return SbFileDelete(dir); } +inline int RmDir(const char* dir) { return rmdir(dir); } inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } inline const char* StrNCpy(char* dest, const char* src, size_t n) { diff --git a/third_party/icu/BUILD.gn b/third_party/icu/BUILD.gn index 61fe28297568..581578eea9df 100644 --- a/third_party/icu/BUILD.gn +++ b/third_party/icu/BUILD.gn @@ -342,7 +342,10 @@ template("generate_icuuc") { defines += [ "U_ICUDATAENTRY_IN_COMMON" ] if (is_starboard) { - public_deps = [ "//starboard:starboard_headers_only" ] + public_deps = [ + "//starboard:starboard_headers_only", + "//starboard/common:common", + ] defines += [ "U_HAVE_NL_LANGINFO_CODESET=0", "U_HAVE_NL_LANGINFO=0" diff --git a/third_party/musl/src/starboard/sys/stat.c b/third_party/musl/src/starboard/sys/stat.c index a41d4fe2d39f..81da1b228d2f 100644 --- a/third_party/musl/src/starboard/sys/stat.c +++ b/third_party/musl/src/starboard/sys/stat.c @@ -37,11 +37,13 @@ int stat(const char *path, struct stat *file_info) return -1; } - file_info -> st_mode = 0; + // In SB_API_VERSION < 16, all files are opened with S_IRUSR | S_IWUSR. + // See starboard/shared/posix/impl/file_open.h. + file_info->st_mode = S_IRUSR | S_IWUSR; if (out_info.is_directory){ - file_info->st_mode = S_IFDIR; + file_info->st_mode |= S_IFDIR; } else if (out_info.is_symbolic_link){ - file_info->st_mode = S_IFLNK; + file_info->st_mode |= S_IFLNK; } file_info->st_ctime = WindowsUsecToTimeT(out_info.creation_time); diff --git a/third_party/skia/src/gpu/text/GrAtlasManager.cpp b/third_party/skia/src/gpu/text/GrAtlasManager.cpp index f2b421a1c56b..b40321a4571d 100644 --- a/third_party/skia/src/gpu/text/GrAtlasManager.cpp +++ b/third_party/skia/src/gpu/text/GrAtlasManager.cpp @@ -14,7 +14,7 @@ #include "src/gpu/text/GrStrikeCache.h" #if defined(STARBOARD) -#include "starboard/file.h" +#include #endif GrAtlasManager::GrAtlasManager(GrProxyProvider* proxyProvider, @@ -254,7 +254,7 @@ static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrCo // remove any previous version of this file remove(filename); #else - SbFileDelete(filename); + unlink(filename); #endif SkFILEWStream file(filename); @@ -263,7 +263,7 @@ static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrCo #if !defined(STARBOARD) remove(filename); // remove any partial file #else - SbFileDelete(filename); + unlink(filename); #endif return false; } @@ -273,7 +273,7 @@ static bool save_pixels(GrDirectContext* dContext, GrSurfaceProxyView view, GrCo #if !defined(STARBOARD) remove(filename); // remove any partial file #else - SbFileDelete(filename); + unlink(filename); #endif return false; } diff --git a/third_party/skia/src/ports/SkFontHost_FreeType_common.cpp b/third_party/skia/src/ports/SkFontHost_FreeType_common.cpp index 92a16991402f..9e6f38155d67 100644 --- a/third_party/skia/src/ports/SkFontHost_FreeType_common.cpp +++ b/third_party/skia/src/ports/SkFontHost_FreeType_common.cpp @@ -49,6 +49,9 @@ #endif #endif +// To avoid SkPath->close() being redef to sb_close. +#undef close + // FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA // were introduced in FreeType 2.5.0. // The following may be removed once FreeType 2.5.0 is required to build. diff --git a/third_party/zlib/BUILD.gn b/third_party/zlib/BUILD.gn index f6a082af51b4..187dc3c90c09 100644 --- a/third_party/zlib/BUILD.gn +++ b/third_party/zlib/BUILD.gn @@ -481,7 +481,7 @@ static_library("minizip") { "contrib/minizip/iostarboard.c", "contrib/minizip/iostarboard.h", ] - deps += [ "//starboard:starboard_headers_only" ] + deps += [ "//starboard/common:file_wrapper" ] } else { configs -= [ "//build/config/compiler:chromium_code" ] } diff --git a/third_party/zlib/contrib/minizip/iostarboard.c b/third_party/zlib/contrib/minizip/iostarboard.c index fb11d8af1231..7cbecfb231b3 100644 --- a/third_party/zlib/contrib/minizip/iostarboard.c +++ b/third_party/zlib/contrib/minizip/iostarboard.c @@ -14,9 +14,12 @@ // Starboard IO base function header for compress/uncompress .zip +#include +#include + #include "zlib.h" #include "iostarboard.h" -#include "starboard/file.h" +#include "starboard/common/file_wrapper.h" static voidpf ZCALLBACK starboard_open_file_func OF((voidpf opaque, const char* filename, int mode)); static voidpf ZCALLBACK starboard_open64_file_func OF((voidpf opaque, const void* filename, int mode)); @@ -28,47 +31,47 @@ static int ZCALLBACK starboard_close_file_func OF((voidpf opaque, voidpf str static int ZCALLBACK starboard_error_file_func OF((voidpf opaque, voidpf stream)); static voidpf ZCALLBACK starboard_open_file_func (voidpf opaque, const char* filename, int mode) { - SbFile file = NULL; int flags = 0; if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) { - flags = kSbFileRead | kSbFileOpenOnly; + flags = O_RDONLY; } else if (mode & ZLIB_FILEFUNC_MODE_EXISTING){ - flags = kSbFileRead | kSbFileWrite | kSbFileOpenOnly; + flags = O_RDWR; } else if (mode & ZLIB_FILEFUNC_MODE_CREATE) { - flags = kSbFileRead | kSbFileWrite | kSbFileCreateAlways; + flags = O_RDWR | O_CREAT | O_TRUNC; } - if ((filename!=NULL) && (flags != 0)) { - file = SbFileOpen(filename, flags, NULL, NULL); + FilePtr file = NULL; + if (filename != NULL) { + file = file_open((const char*)filename, flags); } return file; } static voidpf ZCALLBACK starboard_open64_file_func (voidpf opaque, const void* filename, int mode) { - SbFile file = NULL; int flags = 0; if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) { - flags = kSbFileRead | kSbFileOpenOnly; + flags = O_RDONLY; } else if (mode & ZLIB_FILEFUNC_MODE_EXISTING){ - flags = kSbFileRead | kSbFileWrite | kSbFileOpenOnly; + flags = O_RDWR; } else if (mode & ZLIB_FILEFUNC_MODE_CREATE) { - flags = kSbFileRead | kSbFileWrite | kSbFileCreateAlways; + flags = O_RDWR | O_CREAT | O_TRUNC; } - if ((filename!=NULL) && (flags != 0)) { - file = SbFileOpen((const char*)filename, flags, NULL, NULL); + FilePtr file = NULL; + if (filename != NULL) { + file = file_open((const char*)filename, flags); } return file; } static uLong ZCALLBACK starboard_read_file_func (voidpf opaque, voidpf stream, void* buf, uLong size) { uLong ret = 0; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } if (file != NULL) { - int bytes_read = SbFileRead(file, (char*)buf, (int)size); + int bytes_read = read(file->fd, (char*)buf, (int)size); ret = (uLong)(bytes_read == -1 ? 0 : bytes_read); } return ret; @@ -76,12 +79,12 @@ static uLong ZCALLBACK starboard_read_file_func (voidpf opaque, voidpf stream, v static uLong ZCALLBACK starboard_write_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size) { uLong ret = 0; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } if (file != NULL) { - int bytes_written = SbFileWrite(file, (const char*)buf, (int)size); + int bytes_written = write(file->fd, (const char*)buf, (int)size); ret = (uLong)(bytes_written == -1 ? 0 : bytes_written); } return ret; @@ -89,51 +92,51 @@ static uLong ZCALLBACK starboard_write_file_func (voidpf opaque, voidpf stream, static long ZCALLBACK starboard_tell_file_func (voidpf opaque, voidpf stream) { long ret = -1; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } if (file != NULL) { - ret = SbFileSeek(file, kSbFileFromCurrent, 0); + ret = lseek(file->fd, 0, SEEK_CUR); } return ret; } static ZPOS64_T ZCALLBACK starboard_tell64_file_func (voidpf opaque, voidpf stream) { ZPOS64_T ret = -1; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } if (file != NULL) { - ret = (ZPOS64_T)SbFileSeek(file, kSbFileFromCurrent, 0); + ret = (ZPOS64_T)lseek(file->fd, 0, SEEK_CUR); } return ret; } static long ZCALLBACK starboard_seek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin) { long ret = -1; - SbFile file = NULL; - SbFileWhence file_whence = 0; + FilePtr file = NULL; + int file_whence = 0; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } switch (origin) { case ZLIB_FILEFUNC_SEEK_CUR : - file_whence = kSbFileFromCurrent; + file_whence = SEEK_CUR; break; case ZLIB_FILEFUNC_SEEK_END : - file_whence = kSbFileFromEnd; + file_whence = SEEK_END; break; case ZLIB_FILEFUNC_SEEK_SET : - file_whence = kSbFileFromBegin; + file_whence = SEEK_SET; break; default: return -1; } if (file != NULL) { - if (SbFileSeek(file, file_whence, (int64_t)offset) != -1) { + if (lseek(file->fd, (int64_t)offset, file_whence) != -1) { ret = 0; } } @@ -142,27 +145,27 @@ static long ZCALLBACK starboard_seek_file_func (voidpf opaque, voidpf stream, uL static long ZCALLBACK starboard_seek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { long ret = -1; - SbFile file = NULL; - SbFileWhence file_whence = 0; + FilePtr file = NULL; + int file_whence = 0; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } switch (origin) { case ZLIB_FILEFUNC_SEEK_CUR : - file_whence = kSbFileFromCurrent; + file_whence = SEEK_CUR; break; case ZLIB_FILEFUNC_SEEK_END : - file_whence = kSbFileFromEnd; + file_whence = SEEK_END; break; case ZLIB_FILEFUNC_SEEK_SET : - file_whence = kSbFileFromBegin; + file_whence = SEEK_SET; break; default: return -1; } if (file != NULL) { - if (SbFileSeek(file, file_whence, (int64_t)offset) != -1) { + if (lseek(file->fd, (int64_t)offset, file_whence) != -1) { ret = 0; } } @@ -171,11 +174,11 @@ static long ZCALLBACK starboard_seek64_file_func (voidpf opaque, voidpf stream, static int ZCALLBACK starboard_close_file_func (voidpf opaque, voidpf stream) { int ret = -1; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } - if (file != NULL && SbFileClose(file)) { + if (file != NULL && !file_close(file)) { ret = 0; } return ret; @@ -186,9 +189,9 @@ static int ZCALLBACK starboard_error_file_func (voidpf opaque, voidpf stream) { // the file error code in SbFileOpen, but zlib uses this function to get the file error code // only after reading a file (SbFileRead), which doesn't set the error code anyways. int ret = -1; - SbFile file = NULL; + FilePtr file = NULL; if (stream != NULL) { - file = (SbFile)stream; + file = (FilePtr)stream; } if (file != NULL) { ret = 0;