代码中为什么是55,context->Message_Block_Index > 55
时间: 2024-06-07 22:06:18 浏览: 5
这里的55是因为SHA-1算法中对消息进行填充时需要满足的条件之一是,消息的长度需要在64字节的整数倍上加上8字节的长度表示。而在代码中,每次输入消息的最大长度是64字节,因此当消息块中的字节数小于56字节时,需要填充的字节数为56字节减去消息块中的字节数;当消息块中的字节数大于等于56字节时,需要填充的字节数为64字节减去消息块中的字节数。因此,当消息块中的字节数大于55字节时,需要填充的字节数至少为9字节,即需要增加一个新的消息块来进行填充。因此在代码中出现了 `context->Message_Block_Index > 55` 的判断。
相关问题
if( src_point != NULL ) { src_point[cd_make->dest_index].X = (int32_t)(dl_context.rect.width * cd_make->h_CP) + (int32_t)(((float32_t)dl_context.rect.width * dl_context.mesh_width * (float32_t)cd_make->h_count) + GRPH_CD_OFFSET_TO_ROUND); src_point[cd_make->dest_index].Y = (int32_t)((dl_context.rect.height * cd_make->v_CP) + ((uint32_t)GRPH_CD_MESH_HEIGHT_DEFAULT * cd_make->v_count)); } dest_point[cd_make->dest_index].X = (int32_t)((cd_make->pos[cd_make->pos_index].h_CP_position * GRPH_CD_DST_POINT_SCALE) + GRPH_CD_OFFSET_TO_ROUND); dest_point[cd_make->dest_index].Y = (int32_t)((cd_make->pos[cd_make->pos_index].v_CP_position * GRPH_CD_DST_POINT_SCALE) + GRPH_CD_OFFSET_TO_ROUND);错误为将基本类型的复合表达式转换为无符号的基本类型,修正
要修正错误,您可以将基本类型的复合表达式转换为无符号基本类型。在这种情况下,您可以使用类型转换操作符来执行转换。以下是修改后的代码示例:
```c
if (src_point != NULL) {
src_point[cd_make->dest_index].X = (int32_t)(dl_context.rect.width * cd_make->h_CP) +
(int32_t)(((float32_t)dl_context.rect.width * dl_context.mesh_width * (float32_t)cd_make->h_count) + (uint32_t)GRPH_CD_OFFSET_TO_ROUND);
src_point[cd_make->dest_index].Y = (int32_t)((dl_context.rect.height * cd_make->v_CP) + ((uint32_t)GRPH_CD_MESH_HEIGHT_DEFAULT * cd_make->v_count));
}
dest_point[cd_make->dest_index].X = (int32_t)((cd_make->pos[cd_make->pos_index].h_CP_position * GRPH_CD_DST_POINT_SCALE) + (uint32_t)GRPH_CD_OFFSET_TO_ROUND);
dest_point[cd_make->dest_index].Y = (int32_t)((cd_make->pos[cd_make->pos_index].v_CP_position * GRPH_CD_DST_POINT_SCALE) + (uint32_t)GRPH_CD_OFFSET_TO_ROUND);
```
在这里,我们使用 `(uint32_t)` 将 `GRPH_CD_OFFSET_TO_ROUND` 转换为无符号基本类型。这样就可以将结果赋给对应的变量,并修复了错误。
ret = ffurl_alloc(&whip_uc, s->url, AVIO_FLAG_READ_WRITE, &s->interrupt_callback); if (ret < 0) { av_log(s, AV_LOG_ERROR, "Failed to alloc HTTP context: %s\n", s->url); goto end; } if (!rtc->sdp_offer || !strlen(rtc->sdp_offer)) { av_log(s, AV_LOG_ERROR, "No offer to exchange\n"); ret = AVERROR(EINVAL); goto end; } snprintf(buf, sizeof(buf), "Cache-Control: no-cache\r\n" "Content-Type: application/sdp\r\n"); av_opt_set(whip_uc->priv_data, "headers", buf, 0); av_opt_set(whip_uc->priv_data, "chunked_post", "0", 0); av_opt_set_bin(whip_uc->priv_data, "post_data", rtc->sdp_offer, (int)strlen(rtc->sdp_offer), 0);怎么用上述方法改写
上述代码是使用 FFmpeg 库中的 `ffurl_alloc` 函数创建一个 HTTP 连接,并发送一个带有 SDP offer 的 POST 请求。如果你要使用 `libsoup` 库代替 FFmpeg 库,可以按照以下步骤进行修改:
1. 创建 `SoupSession` 对象
首先,需要使用 `soup_session_new` 函数创建一个 `SoupSession` 对象,它将用于发送 HTTP 请求。
```c
SoupSession *session = soup_session_new ();
```
2. 创建 `SoupMessage` 对象并设置请求头和请求体
然后,需要使用 `soup_message_new` 函数创建一个 `SoupMessage` 对象,并使用 `soup_message_headers_append` 函数设置请求头。最后,使用 `soup_message_set_request` 函数设置请求体。
```c
SoupMessage *msg = soup_message_new ("POST", s->url);
soup_message_headers_append (msg->request_headers, "Cache-Control", "no-cache");
soup_message_headers_append (msg->request_headers, "Content-Type", "application/sdp");
soup_message_set_request (msg, "application/sdp", SOUP_MEMORY_COPY, rtc->sdp_offer, strlen (rtc->sdp_offer));
```
3. 发送 HTTP 请求
使用 `soup_session_send_message` 函数将该消息发送到服务器,并等待响应。如果需要在发送请求时设置超时时间,可以使用 `soup_session_send_message_async` 函数。
```c
SoupMessage *response = soup_session_send_message (session, msg);
```
4. 处理响应
在收到服务器的响应后,需要使用 `soup_message_body_flatten` 函数将响应体转换为字符串,并进行相应的处理。
```c
if (SOUP_STATUS_IS_SUCCESSFUL (response->status_code)) {
gchar *response_body = soup_message_body_flatten (response->response_body, NULL);
// 处理响应体
g_free (response_body);
} else {
// 处理错误
}
```
最终代码如下:
```c
#include <libsoup/soup.h>
...
int send_post_request(const char *url, const char *sdp_offer) {
SoupSession *session = soup_session_new ();
SoupMessage *msg = soup_message_new ("POST", url);
soup_message_headers_append (msg->request_headers, "Cache-Control", "no-cache");
soup_message_headers_append (msg->request_headers, "Content-Type", "application/sdp");
soup_message_set_request (msg, "application/sdp", SOUP_MEMORY_COPY, sdp_offer, strlen (sdp_offer));
SoupMessage *response = soup_session_send_message (session, msg);
if (SOUP_STATUS_IS_SUCCESSFUL (response->status_code)) {
gchar *response_body = soup_message_body_flatten (response->response_body, NULL);
// 处理响应体
g_free (response_body);
return 0;
} else {
// 处理错误
return -1;
}
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![none](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)