Skip to content

Commit

Permalink
feat(live/transcoding): transcoding resource support new fields
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyangyang222 committed Dec 13, 2024
1 parent c88adf3 commit c548b15
Show file tree
Hide file tree
Showing 3 changed files with 243 additions and 59 deletions.
51 changes: 46 additions & 5 deletions docs/resources/live_transcoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ Changing this parameter will create a new resource.

* `video_encoding` - (Required, String) Specifies the video codec. The valid values are **H264** and **H265**.

* `templates` - (Required, List) Specifies the video quality templates.
The [object](#templates_resource) structure is documented below. A maximum of `4` templates can be added.
For resolution and bitrate settings in the presets,
please refer to the [document](https://support.huaweicloud.com/intl/en-us/usermanual-live/live01000802.html).
* `templates` - (Required, List) Specifies the video quality templates. A maximum of `4` templates can be added.
The [templates](#transcoding_templates) structure is documented below.
For resolution and bitrate settings in the presets,
please refer to the [document](https://support.huaweicloud.com/intl/en-us/usermanual-live/live01000802.html).

* `trans_type` - (Optional, String) Specifies the transcoding stream trigger mode.
The valid values are as follows:
+ **play**: Pull stream triggers transcoding.
+ **publish**: Push stream triggers transcoding.

Defaults to **play**.

* `low_bitrate_hd` - (Optional, Bool) Specifies whether to enable low bitrate HD rates. If enabled
the output media will have a lower bitrate with the same image quality. Defaults to **false**.

<a name="templates_resource"></a>
<a name="transcoding_templates"></a>
The `templates` block supports:

* `name` - (Required, String) Specifies the template name. The name can contain a maximum of 64 characters, and only
Expand All @@ -77,6 +84,40 @@ contains letters, digits and hyphens (-).
* `frame_rate` - (Optional, Int) Specifies the frame rate of the transcoded video, in fps. Value range: `0` ~ `30`.
Value 0 indicates that the frame rate remains unchanged.

* `protocol` - (Optional, String) Specifies the protocol type supported for transcoding output.
The valid value is **RTMP**. Defaults to **RTMP**.

* `i_frame_interval` - (Optional, String) Specifies the maximum I-frame interval in frames.
The value ranges from `0` to `500`, includes `0` and `500`. Defaults to `50`.

-> If you want to set the i-frame interval through `i_frame_interval`, please set the `gop` to `0` or do not pass the
`gop` parameter.

* `gop` - (Optional, String) Specifies the interval time for I-frames, in seconds.
The value ranges from `0` to `10`, includes `0` and `10`. Defaults to `2`.

-> When `gop` is not `0`, the i-frame interval is set with the `gop` parameter, and the `i_frame_interval` field does
not take effect.

* `bitrate_adaptive` - (Optional, String) Specifies the adaptive bitrate.
The valid values are as follows:
+ **off**: Disable rate adaptation and output the target rate according to the set rate.
+ **minimum**: Output the target bitrate based on the minimum value of the set bitrate and source file bitrate.
+ **adaptive**: Adaptive output of target bitrate based on source file bitrate.

Defaults to **off**.

* `i_frame_policy` - (Optional, String) Specifies the encoding output I-frame strategy.
The valid values are as follows:
+ **auto**: I-frame output according to the set `gop` duration.
+ **strictSync**: The encoded output I-frame is completely consistent with the source, and the `gop` parameter is
invalid after setting this value.

Defaults to **auto**.

-> In multi bitrate scenarios, it is recommended to enable I-frame random source to ensure alignment of multi bitrate
I-frames.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

"github.com/chnsz/golangsdk"

"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/live/v1/model"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
Expand All @@ -19,117 +21,159 @@ func getTranscodingResourceFunc(conf *config.Config, state *terraform.ResourceSt
return nil, fmt.Errorf("error creating Live v1 client: %s", err)
}

domain := state.Primary.Attributes["domain_name"]
appName := state.Primary.Attributes["app_name"]
return client.ShowTranscodingsTemplate(&model.ShowTranscodingsTemplateRequest{
Domain: domain,
AppName: &appName,
})
var (
domain = state.Primary.Attributes["domain_name"]
appName = state.Primary.Attributes["app_name"]
getOpts = &model.ShowTranscodingsTemplateRequest{
Domain: domain,
AppName: &appName,
}
)
resp, err := client.ShowTranscodingsTemplate(getOpts)
if err != nil {
return nil, fmt.Errorf("error retrieving Live transcoding: %s", err)
}

if resp.Templates == nil || len(*resp.Templates) == 0 {
return nil, golangsdk.ErrDefault404{}
}

return resp, nil
}

func TestAccTranscoding_basic(t *testing.T) {
var obj model.ShowTranscodingsTemplateResponse
var (
obj model.ShowTranscodingsTemplateResponse
rName = "huaweicloud_live_transcoding.test"
appName = acceptance.RandomAccResourceName()
)

pushDomainName := fmt.Sprintf("%s.huaweicloud.com", acceptance.RandomAccResourceNameWithDash())
rName := "huaweicloud_live_transcoding.test"
rc := acceptance.InitResourceCheck(
rName,
&obj,
getTranscodingResourceFunc,
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckLiveIngestRTMPDomainName(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testTranscoding_basic(pushDomainName),
Config: testTranscoding_basic(appName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(rName, "domain_name", pushDomainName),
resource.TestCheckResourceAttr(rName, "app_name", "live"),
resource.TestCheckResourceAttr(rName, "domain_name", acceptance.HW_LIVE_INGEST_RTMP_DOMAIN_NAME),
resource.TestCheckResourceAttr(rName, "app_name", appName),
resource.TestCheckResourceAttr(rName, "video_encoding", "H264"),
resource.TestCheckResourceAttr(rName, "trans_type", "publish"),
resource.TestCheckResourceAttr(rName, "low_bitrate_hd", "false"),
resource.TestCheckResourceAttr(rName, "templates.#", "1"),
resource.TestCheckResourceAttr(rName, "templates.0.name", "t1"),
resource.TestCheckResourceAttr(rName, "templates.0.width", "300"),
resource.TestCheckResourceAttr(rName, "templates.0.height", "400"),
resource.TestCheckResourceAttr(rName, "templates.0.bitrate", "300"),
resource.TestCheckResourceAttr(rName, "templates.0.protocol", "RTMP"),
resource.TestCheckResourceAttr(rName, "templates.0.i_frame_interval", "500"),
resource.TestCheckResourceAttr(rName, "templates.0.gop", "0"),
resource.TestCheckResourceAttr(rName, "templates.0.bitrate_adaptive", "adaptive"),
resource.TestCheckResourceAttr(rName, "templates.0.i_frame_policy", "strictSync"),
),
},
{
Config: testTranscoding_update(pushDomainName),
Config: testTranscoding_update(appName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(rName, "domain_name", pushDomainName),
resource.TestCheckResourceAttr(rName, "app_name", "live"),
resource.TestCheckResourceAttr(rName, "domain_name", acceptance.HW_LIVE_INGEST_RTMP_DOMAIN_NAME),
resource.TestCheckResourceAttr(rName, "app_name", appName),
resource.TestCheckResourceAttr(rName, "video_encoding", "H264"),
resource.TestCheckResourceAttr(rName, "trans_type", "play"),
resource.TestCheckResourceAttr(rName, "low_bitrate_hd", "true"),
resource.TestCheckResourceAttr(rName, "templates.#", "2"),
resource.TestCheckResourceAttr(rName, "templates.0.protocol", "RTMP"),
resource.TestCheckResourceAttr(rName, "templates.0.i_frame_interval", "0"),
resource.TestCheckResourceAttr(rName, "templates.0.gop", "10"),
resource.TestCheckResourceAttr(rName, "templates.0.bitrate_adaptive", "minimum"),
resource.TestCheckResourceAttr(rName, "templates.0.i_frame_policy", "auto"),
resource.TestCheckResourceAttr(rName, "templates.1.name", "t2"),
resource.TestCheckResourceAttr(rName, "templates.1.width", "600"),
resource.TestCheckResourceAttr(rName, "templates.1.height", "800"),
resource.TestCheckResourceAttr(rName, "templates.1.bitrate", "300"),
resource.TestCheckResourceAttr(rName, "templates.1.protocol", "RTMP"),
resource.TestCheckResourceAttr(rName, "templates.1.gop", "10"),
resource.TestCheckResourceAttr(rName, "templates.1.bitrate_adaptive", "off"),
resource.TestCheckResourceAttr(rName, "templates.1.i_frame_policy", "auto"),
),
},
{
ResourceName: rName,
ImportState: true,
ImportStateVerify: true,
ImportStateId: fmt.Sprintf("%s/live", pushDomainName),
ImportStateId: fmt.Sprintf("%s/%s", acceptance.HW_LIVE_INGEST_RTMP_DOMAIN_NAME, appName),
ImportStateVerifyIgnore: []string{
"trans_type",
},
},
},
})
}

func testTranscoding_basic(pushDomainName string) string {
func testTranscoding_basic(appName string) string {
return fmt.Sprintf(`
resource "huaweicloud_live_domain" "ingestDomain" {
name = "%s"
type = "push"
}
resource "huaweicloud_live_transcoding" "test" {
domain_name = huaweicloud_live_domain.ingestDomain.name
app_name = "live"
domain_name = "%[1]s"
app_name = "%[2]s"
video_encoding = "H264"
trans_type = "publish"
templates {
name = "t1"
width = 300
height = 400
bitrate = 300
name = "t1"
width = 300
height = 400
bitrate = 300
protocol = "RTMP"
i_frame_interval = 500
gop = 0
bitrate_adaptive = "adaptive"
i_frame_policy = "strictSync"
}
}
`, pushDomainName)
`, acceptance.HW_LIVE_INGEST_RTMP_DOMAIN_NAME, appName)
}

func testTranscoding_update(pushDomainName string) string {
func testTranscoding_update(appName string) string {
return fmt.Sprintf(`
resource "huaweicloud_live_domain" "ingestDomain" {
name = "%s"
type = "push"
}
resource "huaweicloud_live_transcoding" "test" {
domain_name = huaweicloud_live_domain.ingestDomain.name
app_name = "live"
domain_name = "%[1]s"
app_name = "%[2]s"
video_encoding = "H264"
trans_type = "play"
low_bitrate_hd = true
templates {
name = "t1"
width = 300
height = 400
bitrate = 300
name = "t1"
width = 300
height = 400
bitrate = 300
protocol = "RTMP"
i_frame_interval = 0
gop = 10
bitrate_adaptive = "minimum"
i_frame_policy = "auto"
}
templates {
name = "t2"
width = 600
height = 800
bitrate = 300
name = "t2"
width = 600
height = 800
bitrate = 300
protocol = "RTMP"
gop = 10
bitrate_adaptive = "off"
i_frame_policy = "auto"
}
}
`, pushDomainName)
`, acceptance.HW_LIVE_INGEST_RTMP_DOMAIN_NAME, appName)
}
Loading

0 comments on commit c548b15

Please sign in to comment.