You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.9 KiB

  1. // Copyright (c) 2021 Ximalaya Speech Team (Xiang Lyu)
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <grpcpp/ext/proto_server_reflection_plugin.h>
  15. #include <grpcpp/grpcpp.h>
  16. #include <grpcpp/health_check_service_interface.h>
  17. #include "decoder/params.h"
  18. #include "grpc/grpc_server.h"
  19. DEFINE_int32(port, 10086, "grpc listening port");
  20. DEFINE_int32(workers, 4, "grpc num workers");
  21. using grpc::Server;
  22. using grpc::ServerBuilder;
  23. int main(int argc, char* argv[]) {
  24. gflags::ParseCommandLineFlags(&argc, &argv, false);
  25. google::InitGoogleLogging(argv[0]);
  26. auto decode_config = wenet::InitDecodeOptionsFromFlags();
  27. auto feature_config = wenet::InitFeaturePipelineConfigFromFlags();
  28. auto decode_resource = wenet::InitDecodeResourceFromFlags();
  29. wenet::GrpcServer service(feature_config, decode_config, decode_resource);
  30. grpc::EnableDefaultHealthCheckService(true);
  31. grpc::reflection::InitProtoReflectionServerBuilderPlugin();
  32. ServerBuilder builder;
  33. std::string address("0.0.0.0:" + std::to_string(FLAGS_port));
  34. builder.AddListeningPort(address, grpc::InsecureServerCredentials());
  35. builder.RegisterService(&service);
  36. builder.SetSyncServerOption(ServerBuilder::SyncServerOption::NUM_CQS,
  37. FLAGS_workers);
  38. std::unique_ptr<Server> server(builder.BuildAndStart());
  39. LOG(INFO) << "Listening at port " << FLAGS_port;
  40. server->Wait();
  41. google::ShutdownGoogleLogging();
  42. return 0;
  43. }